<?php
/*
 * 	Manhali - Free Course Management System
 *	tutorials.php
 *	2009-04-19 13:34
 * 	Author: El Haddioui Ismail <ismail.elhaddioui@gmail.com>
 * 	Copyright (C) 2009-2011  El Haddioui Ismail. All rights reserved
 * 	License : GNU/GPL v3

This file is part of Manhali

Manhali is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Manhali is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Manhali.  If not, see <http://www.gnu.org/licenses/>.

*/

defined("access_const") or die( 'Restricted access' );

if (isset($_SESSION['connect']["log"]) && $_SESSION['connect']["log"] == 1 && isset($grade_user_session) && $grade_user_session == "0"){

	echo "<div id=\"titre\">".gestion_tutoriels."</div>";

	echo "<script language=\"javascript\" type=\"text/javascript\" src=\"../jscripts/tiny_mce/tiny_mce.js\"></script>";
	include_once ("tinymce_init.php");
	
	confirmer();

	$max_len = 70;
	$max_len2 = 100;

	if (isset($_GET['l']) && ctype_digit($_GET['l']))
		$page = intval($_GET['l']);
	else $page = 1;
	
	if (isset($_GET['id_tuto']) && ctype_digit($_GET['id_tuto']))
		$id_tuto = intval($_GET['id_tuto']);
	else $id_tuto = 0;

	if (isset($_GET['id_part']) && ctype_digit($_GET['id_part']))
		$id_part = intval($_GET['id_part']);
	else $id_part = 0;

	if (isset($_GET['id_chap']) && ctype_digit($_GET['id_chap']))
		$id_chap = intval($_GET['id_chap']);
	else $id_chap = 0;

	if (isset($_GET['id_bloc']) && ctype_digit($_GET['id_bloc']))
		$id_bloc = intval($_GET['id_bloc']);
	else $id_bloc = 0;

	if (isset($_GET['id_qcm']) && ctype_digit($_GET['id_qcm']))
		$id_qcm = intval($_GET['id_qcm']);
	else $id_qcm = 0;
	
	if (isset($_GET['do'])) $do = $_GET['do'];
	else $do="";
	switch ($do){

		// ****************** create_tuto **************************
    case "create_tuto" : {
    	if (isset($_POST['tuto_titre'])){
    	 $tuto_titre = trim($_POST['tuto_titre']);
    	 if (!empty($tuto_titre)){
    		$tuto_titre = escape_string($tuto_titre);
    		$select_tuto_titre = mysql_query("select id_tutoriel from `" . $tblprefix . "tutoriels` where titre_tutoriel = '$tuto_titre';");
 					if (mysql_num_rows($select_tuto_titre) == 0) {
 						$select_max_order = mysql_query("select max(ordre_tutoriel) from `" . $tblprefix . "tutoriels`;");
 						if (mysql_num_rows($select_max_order) == 1)
 							$ordre_tuto = mysql_result($select_max_order,0) + 1;
 						else $ordre_tuto = 1;
 						$time_insert_tuto = time();
 						$inserttuto = "INSERT INTO `" . $tblprefix . "tutoriels` VALUES (NULL,$id_user_session,'$tuto_titre','','','','by','','0',$ordre_tuto,$time_insert_tuto,$time_insert_tuto,0,'*',1,3);";
	          mysql_query($inserttuto,$connect);
	          $select_this_tuto = mysql_query("select id_tutoriel from `" . $tblprefix . "tutoriels` where titre_tutoriel = '$tuto_titre' and date_creation_tutoriel = $time_insert_tuto;");
	          if (mysql_num_rows($select_this_tuto) == 1) {
	          	$id_tuto = mysql_result($select_this_tuto,0);
	          	$link = "?inc=tutorials&do=update_tuto&id_tuto=".$id_tuto;
						}
	          else $link = "?inc=tutorials";
	          redirection(tutoriel_cree,$link,3,"tips",1);
 					} else goback(titre_existe,2,"error",1);
    	  } else goback(titre_vide,2,"error",1);
    	}
    	else {
    		goback_button();
    		echo "<form method=\"POST\" action=\"\">";
	    	echo "<p><u><b>" .titre_tutoriel. "</b></u><br /><br /><input name=\"tuto_titre\" type=\"text\" size=\"50\" maxlength=\"100\"></p>";
	    	echo "<input type=\"submit\" class=\"button\" value=\"" .btnsend. "\"></form>";
   		}
    } break;
   	
   	// ****************** update_tuto **************************
    case "update_tuto" : {
    		$select_tuto_complet = mysql_query("select * from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tuto;");
    		if (mysql_num_rows($select_tuto_complet) == 1) {
    			$tutoriel = mysql_fetch_row($select_tuto_complet);
    			
    			$titre_tuto = html_ent($tutoriel[2]);
    			$objectifs_tuto = $tutoriel[3];
    			$introduction_tuto = $tutoriel[4];
    			$conclusion_tuto = $tutoriel[5];
    			$notes_tuto = $tutoriel[7];
    			$acces_tuto = $tutoriel[13];
    			
    			if ($tutoriel[1] == $id_user_session) {
    			 if ($tutoriel[8] != 2) {
    				if (!empty($_POST['send'])){
    					$tuto_titre = trim($_POST['tuto_titre']);
    					if (!empty($tuto_titre)){
    						$tuto_titre = escape_string($tuto_titre);
    						$tuto_objectifs = escape_string(trim($_POST['tuto_objectifs']));
    						$tuto_introduction = escape_string(trim($_POST['tuto_introduction']));
    						$tuto_conclusion = escape_string(trim($_POST['tuto_conclusion']));
    						$tuto_licence = escape_string($_POST['tuto_licence']);
    						$tuto_notes = escape_string(trim($_POST['tuto_notes']));

								if ($_POST['acces'] == "learner")
    							$tuto_acces = "0";
    						else if ($_POST['acces'] == "classe"){
    							if (!empty($_POST['classes']))
    								$tuto_acces = "-".implode("-",$_POST['classes'])."-";
    							else $tuto_acces = "0";
    						}
    						else $tuto_acces = "*";
    						
    						$select_tuto_titre = mysql_query("select id_tutoriel from `" . $tblprefix . "tutoriels` where titre_tutoriel = '$tuto_titre';");
 								if ((mysql_num_rows($select_tuto_titre) == 0) || (mysql_num_rows($select_tuto_titre) == 1 && mysql_result($select_tuto_titre,0) == $id_tuto)) {
 									$update_tuto = "update `" . $tblprefix . "tutoriels` SET titre_tutoriel = '$tuto_titre', objectifs_tutoriel = '$tuto_objectifs', introduction_tutoriel = '$tuto_introduction', conclusion_tutoriel = '$tuto_conclusion', licence_tutoriel = '$tuto_licence', notes_tutoriel = '$tuto_notes', date_modification_tutoriel = ".time().", acces_tutoriel = '$tuto_acces' where id_tutoriel = $id_tuto;";
 									mysql_query($update_tuto);
 									redirection(tutoriel_modifie,"?inc=tutorials",3,"tips",1);
 								} else goback(titre_existe,2,"error",1);
    					} else goback(titre_vide,2,"error",1);
    				}
    				else {
    					goback_button();
    					echo "<script language=\"javascript\" type=\"text/javascript\" src=\"../styles/selectall.js\"></script>";
    					
    					echo "<form method=\"POST\" action=\"\">";
    					echo "<p><u><b><font color=\"red\">*</font> " .titre_tutoriel. "</b></u><br /><br /><input name=\"tuto_titre\" type=\"text\" size=\"50\" maxlength=\"100\" value=\"".$titre_tuto."\"></p>";

							echo "<p><u><b><font color=\"red\">*</font> ".acces_cours."</b></u><br /><br />";
							echo "\n<input name=\"acces\" type=\"radio\" value=\"all\" onclick=\"disabled_select('classes',true)\"";
							if ($acces_tuto == "*")
							 echo " checked=\"checked\"";
							echo " /><b>".acces_ouvert."</b><br />";
							echo "\n<input name=\"acces\" type=\"radio\" value=\"learner\" onclick=\"disabled_select('classes',true)\"";
							if ($acces_tuto == "0")
							 echo " checked=\"checked\"";
							echo " /><b>".acces_apprenants."</b><br />";
							echo "\n<input name=\"acces\" type=\"radio\" value=\"classe\" onclick=\"disabled_select('classes',false)\"";
							if ($acces_tuto != "*" && $acces_tuto != "0")
							 echo " checked=\"checked\"";
							echo " /><b>".acces_classes." :</b>";
							$tab_classes = explode("-",$acces_tuto);
    					$select_classes = mysql_query("select * from `" . $tblprefix . "classes`;");
					 		if (mysql_num_rows($select_classes) > 0){
					 			echo "<table border=\"0\"><tr><td align=\"center\">";
								echo "<select size=\"5\" name=\"classes[]\" id=\"classes\" multiple=\"multiple\">";
    						while($classe = mysql_fetch_row($select_classes)){
    							$id_classe = $classe[0];
    							$nom_classe = html_ent($classe[1]);
    							echo "\n<option value=\"".$id_classe."\"";
    							if (in_array($id_classe,$tab_classes))
    								echo " selected=\"selected\"";
    							echo ">".$nom_classe."</option>";
    						}
								echo "\n</select><br />";
								echo "<input type=\"button\" value=\"".deselect_all."\" onclick=\"selectAll('classes',false)\" />";
								echo "<br />".hold_down_ctrl."</td></tr></table>";
					 		}
					 		else echo aucune_classe;
					 		
							echo "<br /><u><b>".licence."</b></u>";

							foreach ($licence_tab as $licence) {
								echo "\n<br /><br /><input name=\"tuto_licence\" type=\"radio\" ";
								if ($licence == $tutoriel[6]) echo "checked=\"checked\" ";
								echo "value=\"".$licence."\"> <a target=\"_blank\" title=\"".licence_const($licence)."\" href=\"http://creativecommons.org/licenses/".$licence."/3.0/\"><img src=\"../images/licenses/".$licence.".png\" border=\"0\" alt=\"".licence_const($licence)."\" /></a> ".licence_const($licence);
							}
							echo "\n<p align=\"center\"><a target=\"_blank\" href=\"http://creativecommons.org/licenses/\">".liste_licences."</a></p>\n";

    					echo "<p><u><b>" .objectifs_tuto. "</b></u><br />".remarque_update_objectifs."<br /><br /><textarea name=\"tuto_objectifs\" cols=\"100\" rows=\"10\">".$objectifs_tuto."</textarea></p>";
    					echo "<br /><p><u><b>" .introduction_tuto. "</b></u><br /><br /><textarea name=\"tuto_introduction\" cols=\"100\" rows=\"10\">".$introduction_tuto."</textarea></p>";
    					echo "<br /><p><u><b>" .conclusion_tuto. "</b></u><br /><br /><textarea name=\"tuto_conclusion\" cols=\"100\" rows=\"10\">".$conclusion_tuto."</textarea></p>";
    					echo "<br /><p><u><b>" .notes_tuto2. "</b></u><br /><br /><textarea name=\"tuto_notes\" cols=\"100\" rows=\"10\">".$notes_tuto."</textarea></p>";

    					echo "<input type=\"hidden\" name=\"send\" value=\"ok\">";
    					echo "<br /><input type=\"submit\" class=\"button\" value=\"" .btnsend. "\"></form>";
    					
    					if ($acces_tuto == "*" || $acces_tuto == "0")
    						echo "<script type=\"text/javascript\">disabled_select('classes',true);</script>";
    				}
    			 } else locationhref_admin("?inc=tutorials");
    			} else locationhref_admin("?inc=tutorials");
    		} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** delete_tuto **************************
    case "delete_tuto" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user = mysql_query("select id_user from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tuto;");
    		if (mysql_num_rows($select_user) == 1 && mysql_result($select_user,0) == $id_user_session){
    			$select_parties = mysql_query("select id_partie from `" . $tblprefix . "parties` where id_tutoriel = $id_tuto;");
    			if (mysql_num_rows($select_parties) > 0){
    				while($partie = mysql_fetch_row($select_parties)){
    					$select_chapitres = mysql_query("select id_chapitre from `" . $tblprefix . "chapitres` where id_partie = $partie[0];");
    					if (mysql_num_rows($select_chapitres) > 0){
    						while($chapitre = mysql_fetch_row($select_chapitres)){
    							$delete_bloc = mysql_query("delete from `" . $tblprefix . "blocs` where id_chapitre = $chapitre[0];");
    						}
							}
							$delete_chapitre = mysql_query("delete from `" . $tblprefix . "chapitres` where id_partie = $partie[0];");					
						}
    			}
    			$delete_partie = mysql_query("delete from `" . $tblprefix . "parties` where id_tutoriel = $id_tuto;");
    			$delete_tuto = mysql_query("delete from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tuto;");
    		}
    	}
    	locationhref_admin("?inc=tutorials");
    } break;

    // ****************** publier_tuto *************************
    case "publier_tuto" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$publier_tuto = mysql_query("update `" . $tblprefix . "tutoriels` set publie_tutoriel = '1' where id_tutoriel = $id_tuto and id_user = $id_user_session;");
    	}
    	locationhref_admin("?inc=tutorials");
    } break;

    // ****************** depublier_tuto ***********************
    case "depublier_tuto" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$depublier_tuto = mysql_query("update `" . $tblprefix . "tutoriels` set publie_tutoriel = '0' where id_tutoriel = $id_tuto and id_user = $id_user_session;");
    	}
    	locationhref_admin("?inc=tutorials");
    } break;
    
    // ****************** open_tuto ****************************
    case "open_tuto" : {
			
		 goback_button();
	
     $select_tuto = mysql_query("select titre_tutoriel, publie_tutoriel, notes_tutoriel from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tuto and id_user = $id_user_session;");
     if (mysql_num_rows($select_tuto) == 1) {
    	$titre_tuto = mysql_result($select_tuto,0,0);
    	$publie_tuto = mysql_result($select_tuto,0,1);
    	$notes_tuto = mysql_result($select_tuto,0,2);
			
			$titre_tuto = html_ent($titre_tuto);
			$titre_tuto = readmore($titre_tuto,$max_len2);
			
			echo "<h2><center>".tutoriel." : <u>".$titre_tuto."</u></center></h2>";
						
			if ($publie_tuto == 2)
    		echo "<table border=\"0\"><tr><td><img border=\"0\" src=\"../images/others/add2.png\" /></a></td><td><b>".creer_partie."</b></td></tr></table><br />";
 			else 
 			  echo "<table border=\"0\"><tr><td><a href=\"?inc=tutorials&do=create_partie&id_tuto=".$id_tuto."\"><img border=\"0\" src=\"../images/others/add.png\" /></a></td><td><a href=\"?inc=tutorials&do=create_partie&id_tuto=".$id_tuto."\"><b>".creer_partie."</b></a></td></tr></table><br />";

  $select_my_parties = mysql_query("select id_partie, titre_partie, publie_partie, ordre_partie from `" . $tblprefix . "parties` where id_tutoriel = $id_tuto order by ordre_partie;");
	$nbr_trouve = mysql_num_rows($select_my_parties);
  if ($nbr_trouve > 0){
		$page_max = ceil($nbr_trouve / $nbr_resultats);
		if ($page <= $page_max && $page > 1 && $page_max > 1)
			$limit = ($page - 1) * $nbr_resultats;
		else {
			$limit = 0;
			$page = 1;
		}

    	$select_my_parties_limit = mysql_query("select id_partie, titre_partie, publie_partie, ordre_partie from `" . $tblprefix . "parties` where id_tutoriel = $id_tuto order by ordre_partie limit $limit, $nbr_resultats;");

    		echo "<table width=\"100%\" align=\"center\" style=\"border: 1px solid #000000;\"><tr bgcolor=\"#f1d3bd\">\n";
				echo "\n<td class=\"affichage_table\"><b>".partie."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".editer."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".supprimer."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".previsualiser."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".ordonner."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".action."</b></td>";
				echo "</tr>";
				$i_ordre = ($page - 1) * $nbr_resultats + 1;
				while($partie = mysql_fetch_row($select_my_parties_limit)){
					
					$titre_partie = html_ent($partie[1]);
					$titre_partie = readmore($titre_partie,$max_len2);
					
					if ($partie[2] == 1)
						$color = "green";
					else $color = "red";
					
					echo "<tr>\n";
					echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=open_partie&id_part=".$partie[0]."\" title=\"".ouvrir_partie."\"><font color=\"".$color."\"><u><b>".$titre_partie."</b></u></font></a></td>";

					if ($publie_tuto == 2)
						echo "\n<td class=\"affichage_table\"><img border=\"0\" src=\"../images/others/noedit.png\" width=\"32\" height=\"32\" /></td>";
					else
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=update_partie&id_part=".$partie[0]."\" title=\"".editer."\"><img border=\"0\" src=\"../images/others/edit.png\" width=\"32\" height=\"32\" /></a></td>";

					echo "\n<td class=\"affichage_table\"><a href=\"#\" onClick=\"confirmer('?inc=tutorials&do=delete_partie&id_part=".$partie[0]."&key=".$key."','".confirm_supprimer_partie."')\" title=\"".supprimer."\"><img border=\"0\" src=\"../images/others/delete.png\" width=\"32\" height=\"32\" /></a></td>";

					echo "\n<td class=\"affichage_table\"><a href=\"?inc=view_tuto&tutorial=".$id_tuto."#".$partie[0]."\" title=\"".previsualiser."\"><img border=\"0\" src=\"../images/others/view.png\" width=\"32\" height=\"32\" /></a></td>";

					echo "\n<td class=\"affichage_table\">";
					$partie_precedent = mysql_query ("select id_partie from `" . $tblprefix . "parties` where ordre_partie < $partie[3] and id_tutoriel = $id_tuto order by ordre_partie desc;");
					if (mysql_num_rows($partie_precedent) > 0)
						echo "<a href=\"?inc=tutorials&do=orderup_partie&id_part=".$partie[0]."&key=".$key."\" title=\"".deplacer_haut."\"><img border=\"0\" src=\"../images/others/up.png\" width=\"15\" height=\"15\" /></a>";
					else
						echo "<img border=\"0\" src=\"../images/others/up2.png\" width=\"15\" height=\"15\" />";
					echo "<b> ".$i_ordre." </b>";
					$i_ordre++;
					$partie_suivant = mysql_query ("select id_partie from `" . $tblprefix . "parties` where ordre_partie > $partie[3] and id_tutoriel = $id_tuto order by ordre_partie;");
					if (mysql_num_rows($partie_suivant) > 0)
						echo "<a href=\"?inc=tutorials&do=orderdown_partie&id_part=".$partie[0]."&key=".$key."\" title=\"".deplacer_bas."\"><img border=\"0\" src=\"../images/others/down.png\" width=\"15\" height=\"15\" /></a>";
					else echo "<img border=\"0\" src=\"../images/others/down2.png\" width=\"15\" height=\"15\" />";
					echo "</td>";

					if ($partie[2] == 1)
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=depublier_partie&id_part=".$partie[0]."&key=".$key."\" title=\"".depublier_element."\"><b>".depublier."</b></a></td>";
					else
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=publier_partie&id_part=".$partie[0]."&key=".$key."\" title=\"".publier_element."\"><b>".publier."</b></a></td>";

					echo "</tr>\n";
				}
				echo "\n</table>";

		if ($page_max > 1){
			$page_precedente = $page - 1;
			$page_suivante = $page + 1;
  		echo "<br /><table border=\"0\" align=\"center\"><tr>";
			if ($page_precedente >= 1)
				echo "<td><a href=\"?inc=tutorials&do=open_tuto&id_tuto=".$id_tuto."&l=".$page_precedente."\"><img border=\"0\" src=\"../images/others/precedent.png\" width=\"32\" height=\"32\" /></a></td><td><a href=\"?inc=tutorials&do=open_tuto&id_tuto=".$id_tuto."&l=".$page_precedente."\"><b>".page_precedente."</b></a></td>";
			echo "<td>";
			for($i=1;$i<=$page_max;$i++){
				if ($i != $page) echo "<a href=\"?inc=tutorials&do=open_tuto&id_tuto=".$id_tuto."&l=".$i."\">";
				echo "<b>".$i."</b>";
				if ($i != $page) echo "</a>";
				echo "&nbsp; ";
			}
			echo "</td>";
			if ($page_suivante <= $page_max)
				echo "<td><a href=\"?inc=tutorials&do=open_tuto&id_tuto=".$id_tuto."&l=".$page_suivante."\"><b>".page_suivante."</b></a></td><td><a href=\"?inc=tutorials&do=open_tuto&id_tuto=".$id_tuto."&l=".$page_suivante."\"><img border=\"0\" src=\"../images/others/suivant.png\" width=\"32\" height=\"32\" /></a></td>";
			echo "</tr></table>";
		}
    	} else echo pas_de_partie."<br />";
    	
    	if (!empty($notes_tuto))
    		echo "<br /><u><b>".remarques."</b></u><br />".$notes_tuto."<hr />";
    	
    	if ($publie_tuto == 2)
				echo "<br /><img src=\"../images/icones/info.png\" /> <b>".remarque_partie."</b>";
     } else locationhref_admin("?inc=tutorials");
    } break;
    
    // ****************** create_partie ************************
    case "create_partie" : {
    	
     $select_publie_tuto = mysql_query("select id_user, publie_tutoriel from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tuto;");
     $id_user = mysql_result($select_publie_tuto,0,0);
     $publie_tuto = mysql_result($select_publie_tuto,0,1);
     if ($publie_tuto != 2 && $id_user == $id_user_session) {
    	
    	if (isset($_POST['partie_titre'])){
    	 $partie_titre = trim($_POST['partie_titre']);
    	 if (!empty($partie_titre)){
    		$partie_titre = escape_string($partie_titre);
    		$select_partie_titre = mysql_query("select id_partie from `" . $tblprefix . "parties` where titre_partie = '$partie_titre' and id_tutoriel = $id_tuto;");
 					if (mysql_num_rows($select_partie_titre) == 0) {
 						$select_max_order = mysql_query("select max(ordre_partie) from `" . $tblprefix . "parties` where id_tutoriel = $id_tuto;");
 						if (mysql_num_rows($select_max_order) == 1)
 							$ordre_partie = mysql_result($select_max_order,0) + 1;
 						else $ordre_partie = 1;
 						$insertpartie = "INSERT INTO `" . $tblprefix . "parties` VALUES (NULL,$id_tuto,'$partie_titre','','','','1',$ordre_partie);";
	          mysql_query($insertpartie,$connect);
	          
	          $date_modification_tuto = time();
	          $update_tuto_date_modification = mysql_query("update `" . $tblprefix . "tutoriels` set date_modification_tutoriel = $date_modification_tuto where id_tutoriel = $id_tuto;");

	          $select_this_partie = mysql_query("select id_partie from `" . $tblprefix . "parties` where titre_partie = '$partie_titre' and id_tutoriel = $id_tuto;");
	          if (mysql_num_rows($select_this_partie) == 1) {
	          	$id_part = mysql_result($select_this_partie,0);
	          	$link = "?inc=tutorials&do=update_partie&id_part=".$id_part;
						}
	          else $link = "?inc=tutorials&do=open_tuto&id_tuto=".$id_tuto;
	          redirection(partie_cree,$link,3,"tips",1);
 					} else goback(titre_existe,2,"error",1);
    	  } else goback(titre_vide,2,"error",1);
    	}
    	else {
    		goback_button();
    		echo "<form method=\"POST\" action=\"\">";
	    	echo "<p><u><b>" .titre_partie. "</b></u><br /><br /><input name=\"partie_titre\" type=\"text\" size=\"50\" maxlength=\"100\"></p>";
	    	echo "<input type=\"submit\" class=\"button\" value=\"" .btnsend. "\"></form>";
   		}
   	 } else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** update_partie ************************
    case "update_partie" : {
    	$select_tuto = mysql_query("select `" . $tblprefix . "tutoriels`.id_tutoriel, id_user, publie_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties` where `" . $tblprefix . "parties`.id_tutoriel = `" . $tblprefix . "tutoriels`.id_tutoriel and id_partie = $id_part;");
    	$id_tuto = mysql_result($select_tuto,0,0);
    	$id_user = mysql_result($select_tuto,0,1);
    	$publie_tuto = mysql_result($select_tuto,0,2);
    	if ($publie_tuto != 2 && $id_user == $id_user_session) {
     	
    		$select_partie_complet = mysql_query("select * from `" . $tblprefix . "parties` where id_partie = $id_part;");
    		if (mysql_num_rows($select_partie_complet) == 1) {
    			$partie = mysql_fetch_row($select_partie_complet);
    			
    			$titre_partie = html_ent($partie[2]);
    			$objectifs_partie = $partie[3];
    			$introduction_partie = $partie[4];
    			$conclusion_partie = $partie[5];
    			
    				if (!empty($_POST['send'])){
    					$partie_titre = trim($_POST['partie_titre']);
    					if (!empty($partie_titre)){
    						$partie_titre = escape_string($partie_titre);
    						$partie_objectifs = escape_string(trim($_POST['partie_objectifs']));
    						$partie_introduction = escape_string(trim($_POST['partie_introduction']));
    						$partie_conclusion = escape_string(trim($_POST['partie_conclusion']));
    						$select_partie_titre = mysql_query("select id_partie from `" . $tblprefix . "parties` where titre_partie = '$partie_titre' and id_tutoriel = $id_tuto;");
 								if ((mysql_num_rows($select_partie_titre) == 0) || (mysql_num_rows($select_partie_titre) == 1 && mysql_result($select_partie_titre,0) == $id_part)) {
 									$update_partie = "update `" . $tblprefix . "parties` SET titre_partie = '$partie_titre', objectifs_partie = '$partie_objectifs', introduction_partie = '$partie_introduction', conclusion_partie = '$partie_conclusion' where id_partie = $id_part;";
 									mysql_query($update_partie);
 									
	          			$date_modification_tuto = time();
	          			$update_tuto_date_modification = mysql_query("update `" . $tblprefix . "tutoriels` set date_modification_tutoriel = $date_modification_tuto where id_tutoriel = $id_tuto;");

 									redirection(partie_modifie,"?inc=tutorials&do=open_tuto&id_tuto=".$id_tuto."",3,"tips",1);
 								} else goback(titre_existe,2,"error",1);
    					} else goback(titre_vide,2,"error",1);
    				}
    				else {
    					goback_button();
							echo "<form method=\"POST\" action=\"\">";
    					echo "<p><u><b><font color=\"red\">*</font> " .titre_partie. "</b></u><br /><br /><input name=\"partie_titre\" type=\"text\" size=\"50\" maxlength=\"100\" value=\"".$titre_partie."\"></p>";							
    					echo "<br /><p><u><b>" .objectifs_partie. "</b></u><br />".remarque_update_objectifs."<br /><br /><textarea name=\"partie_objectifs\" cols=\"100\" rows=\"10\">".$objectifs_partie."</textarea></p>";
    					echo "<br /><p><u><b>" .introduction_partie. "</b></u><br /><br /><textarea name=\"partie_introduction\" cols=\"100\" rows=\"10\">".$introduction_partie."</textarea></p>";
    					echo "<br /><p><u><b>" .conclusion_partie. "</b></u><br /><br /><textarea name=\"partie_conclusion\" cols=\"100\" rows=\"10\">".$conclusion_partie."</textarea></p>";
  					
    					echo "<input type=\"hidden\" name=\"send\" value=\"ok\">";
    					echo "<br /><input type=\"submit\" class=\"button\" value=\"" .btnsend. "\"></form>";
    				}
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** delete_partie ************************
    case "delete_partie" : {
			if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idtuto = mysql_query("select id_user, `" . $tblprefix . "tutoriels`.id_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and id_partie = $id_part;");
    		if (mysql_num_rows($select_user_idtuto) == 1 && mysql_result($select_user_idtuto,0,0) == $id_user_session){
    			$id_tutoriel = mysql_result($select_user_idtuto,0,1);
    			$select_chapitres = mysql_query("select id_chapitre from `" . $tblprefix . "chapitres` where id_partie = $id_part;");
    			if (mysql_num_rows($select_chapitres) > 0){
    				while($chapitre = mysql_fetch_row($select_chapitres)){
    					$delete_bloc = mysql_query("delete from `" . $tblprefix . "blocs` where id_chapitre = $chapitre[0];");
    				}
					}
					$delete_chapitre = mysql_query("delete from `" . $tblprefix . "chapitres` where id_partie = $id_part;");					
    			$delete_partie = mysql_query("delete from `" . $tblprefix . "parties` where id_partie = $id_part;");
					
					locationhref_admin("?inc=tutorials&do=open_tuto&id_tuto=".$id_tutoriel);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** orderup_partie **********************
    case "orderup_partie" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$cette_partie = mysql_query ("select id_tutoriel, ordre_partie from `" . $tblprefix . "parties` where id_partie = $id_part;");
				if (mysql_num_rows($cette_partie) == 1) {
					$id_tutoriel = mysql_result($cette_partie,0,0);
					$ordre_partie = mysql_result($cette_partie,0,1);
					
					$select_user = mysql_query("select id_user from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tutoriel;");
					if (mysql_num_rows($select_user) == 1 && mysql_result($select_user,0) == $id_user_session){

    				$partie_precedente = mysql_query ("select id_partie, ordre_partie from `" . $tblprefix . "parties` where ordre_partie < $ordre_partie and id_tutoriel = $id_tutoriel order by ordre_partie desc;");
						if (mysql_num_rows($partie_precedente) > 0) {
							$idpartie_precedente = mysql_result($partie_precedente,0,0);
							$ordrepartie_precedente = mysql_result($partie_precedente,0,1);
							
							$order_this_partie = mysql_query("update `" . $tblprefix . "parties` set ordre_partie = $ordrepartie_precedente where id_partie = $id_part;");
							$order_partie_precedente = mysql_query("update `" . $tblprefix . "parties` set ordre_partie = $ordre_partie where id_partie = $idpartie_precedente;");
						}
    			}
    			locationhref_admin("?inc=tutorials&do=open_tuto&id_tuto=".$id_tutoriel);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** orderdown_partie **********************
    case "orderdown_partie" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$cette_partie = mysql_query ("select id_tutoriel, ordre_partie from `" . $tblprefix . "parties` where id_partie = $id_part;");
				if (mysql_num_rows($cette_partie) == 1) {
					$id_tutoriel = mysql_result($cette_partie,0,0);
					$ordre_partie = mysql_result($cette_partie,0,1);

					$select_user = mysql_query("select id_user from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tutoriel;");
					if (mysql_num_rows($select_user) == 1 && mysql_result($select_user,0) == $id_user_session){
						
    				$partie_suivante = mysql_query ("select id_partie, ordre_partie from `" . $tblprefix . "parties` where ordre_partie > $ordre_partie and id_tutoriel = $id_tutoriel order by ordre_partie;");
						if (mysql_num_rows($partie_suivante) > 0) {
							$idpartie_suivante = mysql_result($partie_suivante,0,0);
							$ordrepartie_suivante = mysql_result($partie_suivante,0,1);
							
							$order_this_partie = mysql_query("update `" . $tblprefix . "parties` set ordre_partie = $ordrepartie_suivante where id_partie = $id_part;");
							$order_partie_suivante = mysql_query("update `" . $tblprefix . "parties` set ordre_partie = $ordre_partie where id_partie = $idpartie_suivante;");
						}
					}
    			locationhref_admin("?inc=tutorials&do=open_tuto&id_tuto=".$id_tutoriel);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;
 
    // ****************** publier_partie ***********************
    case "publier_partie" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idtuto = mysql_query("select id_user, `" . $tblprefix . "tutoriels`.id_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and id_partie = $id_part;");
    		if (mysql_num_rows($select_user_idtuto) == 1 && mysql_result($select_user_idtuto,0,0) == $id_user_session){
    			$id_tutoriel = mysql_result($select_user_idtuto,0,1);
    			$publier_partie = mysql_query("update `" . $tblprefix . "parties` set publie_partie = '1' where id_partie = $id_part;");
    			locationhref_admin("?inc=tutorials&do=open_tuto&id_tuto=".$id_tutoriel);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;
    
    // ****************** depublier_partie *********************
    case "depublier_partie" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idtuto = mysql_query("select id_user, `" . $tblprefix . "tutoriels`.id_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and id_partie = $id_part;");
    		if (mysql_num_rows($select_user_idtuto) == 1 && mysql_result($select_user_idtuto,0,0) == $id_user_session){
    			$id_tutoriel = mysql_result($select_user_idtuto,0,1);
    			$depublier_partie = mysql_query("update `" . $tblprefix . "parties` set publie_partie = '0' where id_partie = $id_part;");
    			locationhref_admin("?inc=tutorials&do=open_tuto&id_tuto=".$id_tutoriel);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;
    
    // ****************** open_partie **************************
    case "open_partie" : {
    		
     $select_tuto = mysql_query("select `" . $tblprefix . "tutoriels`.id_tutoriel, titre_tutoriel, titre_partie, publie_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and id_partie = $id_part and id_user = $id_user_session;");
     if (mysql_num_rows($select_tuto) == 1) {
     	$id_tuto = mysql_result($select_tuto,0,0);
    	$titre_tuto = html_ent(mysql_result($select_tuto,0,1));
    	$titre_tuto = readmore($titre_tuto,$max_len2);
			$titre_part = html_ent(mysql_result($select_tuto,0,2));
			$titre_part = readmore($titre_part,$max_len2);
    	$publie_tuto = mysql_result($select_tuto,0,3);

			goback_button();

			echo "<b>".tutoriel." : <a href=\"?inc=tutorials&do=open_tuto&id_tuto=".$id_tuto."\">".$titre_tuto."</a></b><br />";
			echo "<h2><center>".partie." : <u>".$titre_part."</u></center></h2>";
					
			if ($publie_tuto == 2)
    		echo "<table border=\"0\"><tr><td><img border=\"0\" src=\"../images/others/add2.png\" /></a></td><td><b>".creer_chap."</b></td></tr></table><br />";
 			else 
 			  echo "<table border=\"0\"><tr><td><a href=\"?inc=tutorials&do=create_chapitre&id_part=".$id_part."\"><img border=\"0\" src=\"../images/others/add.png\" /></a></td><td><a href=\"?inc=tutorials&do=create_chapitre&id_part=".$id_part."\"><b>".creer_chap."</b></a></td></tr></table><br />";

  $select_my_chapitres = mysql_query("select id_chapitre, titre_chapitre, publie_chapitre, ordre_chapitre from `" . $tblprefix . "chapitres` where id_partie = $id_part order by ordre_chapitre;");
	$nbr_trouve = mysql_num_rows($select_my_chapitres);
  if ($nbr_trouve > 0){
		$page_max = ceil($nbr_trouve / $nbr_resultats);
		if ($page <= $page_max && $page > 1 && $page_max > 1)
			$limit = ($page - 1) * $nbr_resultats;
		else {
			$limit = 0;
			$page = 1;
		}

    	$select_my_chapitres_limit = mysql_query("select id_chapitre, titre_chapitre, publie_chapitre, ordre_chapitre from `" . $tblprefix . "chapitres` where id_partie = $id_part order by ordre_chapitre limit $limit, $nbr_resultats;");

    		echo "<table width=\"100%\" align=\"center\" style=\"border: 1px solid #000000;\"><tr bgcolor=\"#f1d3bd\">\n";
				echo "\n<td class=\"affichage_table\"><b>".chapitre."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".editer."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".supprimer."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".previsualiser."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".ordonner."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".action."</b></td>";
				echo "</tr>";
				$i_ordre = ($page - 1) * $nbr_resultats + 1;
				while($chapitre = mysql_fetch_row($select_my_chapitres_limit)){
					
					$titre_chapitre = html_ent($chapitre[1]);
					$titre_chapitre = readmore($titre_chapitre,$max_len2);
					
					if ($chapitre[2] == 1)
						$color = "green";
					else $color = "red";
					
					echo "<tr>\n";
					echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$chapitre[0]."\" title=\"".ouvrir_chapitre."\"><font color=\"".$color."\"><u><b>".$titre_chapitre."</b></u></font></a></td>";

					if ($publie_tuto == 2)
						echo "\n<td class=\"affichage_table\"><img border=\"0\" src=\"../images/others/noedit.png\" width=\"32\" height=\"32\" /></td>";
					else
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=update_chapitre&id_chap=".$chapitre[0]."\" title=\"".editer."\"><img border=\"0\" src=\"../images/others/edit.png\" width=\"32\" height=\"32\" /></a></td>";
				
					echo "\n<td class=\"affichage_table\"><a href=\"#\" onClick=\"confirmer('?inc=tutorials&do=delete_chapitre&id_chap=".$chapitre[0]."&key=".$key."','".confirm_supprimer_chapitre."')\" title=\"".supprimer."\"><img border=\"0\" src=\"../images/others/delete.png\" width=\"32\" height=\"32\" /></a></td>";
					
					echo "\n<td class=\"affichage_table\"><a href=\"?inc=view_tuto&chapter=".$chapitre[0]."\" title=\"".previsualiser."\"><img border=\"0\" src=\"../images/others/view.png\" width=\"32\" height=\"32\" /></a></td>";
					
					echo "\n<td class=\"affichage_table\">";
					$chapitre_precedent = mysql_query ("select id_chapitre from `" . $tblprefix . "chapitres` where ordre_chapitre < $chapitre[3] and id_partie = $id_part order by ordre_chapitre desc;");
					if (mysql_num_rows($chapitre_precedent) > 0)
						echo "<a href=\"?inc=tutorials&do=orderup_chapitre&id_chap=".$chapitre[0]."&key=".$key."\" title=\"".deplacer_haut."\"><img border=\"0\" src=\"../images/others/up.png\" width=\"15\" height=\"15\" /></a>";
					else
						echo "<img border=\"0\" src=\"../images/others/up2.png\" width=\"15\" height=\"15\" />";
					echo "<b> ".$i_ordre." </b>";
					$i_ordre++;
					$chapitre_suivant = mysql_query ("select id_chapitre from `" . $tblprefix . "chapitres` where ordre_chapitre > $chapitre[3] and id_partie = $id_part order by ordre_chapitre;");
					if (mysql_num_rows($chapitre_suivant) > 0)
						echo "<a href=\"?inc=tutorials&do=orderdown_chapitre&id_chap=".$chapitre[0]."&key=".$key."\" title=\"".deplacer_bas."\"><img border=\"0\" src=\"../images/others/down.png\" width=\"15\" height=\"15\" /></a>";
					else echo "<img border=\"0\" src=\"../images/others/down2.png\" width=\"15\" height=\"15\" />";
					echo "</td>";
					
					if ($chapitre[2] == 1)
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=depublier_chapitre&id_chap=".$chapitre[0]."&key=".$key."\" title=\"".depublier_element."\"><b>".depublier."</b></a></td>";
					else
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=publier_chapitre&id_chap=".$chapitre[0]."&key=".$key."\" title=\"".publier_element."\"><b>".publier."</b></a></td>";

					echo "</tr>\n";
				}
				echo "\n</table>";

		if ($page_max > 1){
			$page_precedente = $page - 1;
			$page_suivante = $page + 1;
  		echo "<br /><table border=\"0\" align=\"center\"><tr>";
			if ($page_precedente >= 1)
				echo "<td><a href=\"?inc=tutorials&do=open_partie&id_part=".$id_part."&l=".$page_precedente."\"><img border=\"0\" src=\"../images/others/precedent.png\" width=\"32\" height=\"32\" /></a></td><td><a href=\"?inc=tutorials&do=open_partie&id_part=".$id_part."&l=".$page_precedente."\"><b>".page_precedente."</b></a></td>";
			echo "<td>";
			for($i=1;$i<=$page_max;$i++){
				if ($i != $page) echo "<a href=\"?inc=tutorials&do=open_partie&id_part=".$id_part."&l=".$i."\">";
				echo "<b>".$i."</b>";
				if ($i != $page) echo "</a>";
				echo "&nbsp; ";
			}
			echo "</td>";
			if ($page_suivante <= $page_max)
				echo "<td><a href=\"?inc=tutorials&do=open_partie&id_part=".$id_part."&l=".$page_suivante."\"><b>".page_suivante."</b></a></td><td><a href=\"?inc=tutorials&do=open_partie&id_part=".$id_part."&l=".$page_suivante."\"><img border=\"0\" src=\"../images/others/suivant.png\" width=\"32\" height=\"32\" /></a></td>";
			echo "</tr></table>";
		}
		
				if ($publie_tuto == 2)
					echo "<br /><img src=\"../images/icones/info.png\" /> <b>".remarque_chapitre."</b>";
    	} else echo pas_de_chapitre;
     } else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** create_chapitre **********************
    case "create_chapitre" : {
    	$select_publie_user_tuto = mysql_query("select id_user, `" . $tblprefix . "tutoriels`.id_tutoriel, publie_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and id_partie = $id_part;");
     	$id_user = mysql_result($select_publie_user_tuto,0,0);
     	$id_tuto = mysql_result($select_publie_user_tuto,0,1);
     	$publie_tuto = mysql_result($select_publie_user_tuto,0,2);
     	if ($publie_tuto != 2 && $id_user == $id_user_session) {
    	
    	 if (isset($_POST['chapitre_titre'])){
    	 	$chapitre_titre = trim($_POST['chapitre_titre']);
    		if (!empty($chapitre_titre)){
    			$chapitre_titre = escape_string($chapitre_titre);
    		  $select_chapitre_titre = mysql_query("select id_chapitre from `" . $tblprefix . "chapitres` where titre_chapitre = '$chapitre_titre' and id_partie = $id_part;");
 					if (mysql_num_rows($select_chapitre_titre) == 0) {
 						$select_max_order = mysql_query("select max(ordre_chapitre) from `" . $tblprefix . "chapitres` where id_partie = $id_part;");
 						if (mysql_num_rows($select_max_order) == 1)
 							$ordre_chapitre = mysql_result($select_max_order,0) + 1;
 						else $ordre_chapitre = 1;
 						
 						$time_insert_chapitre = time();
 						$insertchapitre = "INSERT INTO `" . $tblprefix . "chapitres` VALUES (NULL,$id_part,'$chapitre_titre','',0,'1',$ordre_chapitre,$time_insert_chapitre,$time_insert_chapitre,1,3);";
	          mysql_query($insertchapitre,$connect);

	          $date_modification_tuto = time();
	          $update_tuto_date_modification = mysql_query("update `" . $tblprefix . "tutoriels` set date_modification_tutoriel = $date_modification_tuto where id_tutoriel = $id_tuto;");

	          $select_this_chapitre = mysql_query("select id_chapitre from `" . $tblprefix . "chapitres` where titre_chapitre = '$chapitre_titre' and date_creation_chapitre = $time_insert_chapitre;");
	          if (mysql_num_rows($select_this_chapitre) == 1) {
	          	$id_chap = mysql_result($select_this_chapitre,0);
	          	$link = "?inc=tutorials&do=update_chapitre&id_chap=".$id_chap;
						}
	          else $link = "?inc=tutorials&do=open_partie&id_part=".$id_part;
	          redirection(chapitre_cree,$link,3,"tips",1);
 					} else goback(titre_existe,2,"error",1);
    		 } else goback(titre_vide,2,"error",1);
    		}
    		else {
    			goback_button();
    			echo "<form method=\"POST\" action=\"\">";
	    		echo "<p><u><b>" .titre_chapitre. "</b></u><br /><br /><input name=\"chapitre_titre\" type=\"text\" size=\"50\" maxlength=\"100\"></p>";
	    		echo "<input type=\"submit\" class=\"button\" value=\"" .btnsend. "\"></form>";
   			}
   		} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** update_chapitre **********************
    case "update_chapitre" : {
    	
    	$select_tuto_partie = mysql_query("select `" . $tblprefix . "chapitres`.id_partie, id_user, publie_tutoriel, `" . $tblprefix . "tutoriels`.id_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres` where `" . $tblprefix . "parties`.id_tutoriel = `" . $tblprefix . "tutoriels`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and id_chapitre = $id_chap;");
    	
    	$id_partie = mysql_result($select_tuto_partie,0,0);
    	$id_user = mysql_result($select_tuto_partie,0,1);
    	$publie_tuto = mysql_result($select_tuto_partie,0,2);
    	$id_tuto = mysql_result($select_tuto_partie,0,3);
    	if ($publie_tuto != 2 && $id_user == $id_user_session) {
     	
    		$select_chapitre_complet = mysql_query("select * from `" . $tblprefix . "chapitres` where id_chapitre = $id_chap;");
    		if (mysql_num_rows($select_chapitre_complet) == 1) {
    			$chapitre = mysql_fetch_row($select_chapitre_complet);
    			
    			$titre_chapitre = html_ent($chapitre[2]);
    			$objectifs_chapitre = $chapitre[3];
    			    			
    				if (!empty($_POST['send'])){
    					$chapitre_titre = trim($_POST['chapitre_titre']);
    					if (!empty($chapitre_titre)){
    						$chapitre_titre = escape_string($chapitre_titre);
    						$chapitre_objectifs = escape_string(trim($_POST['chapitre_objectifs']));
    						$select_chapitre_titre = mysql_query("select id_chapitre from `" . $tblprefix . "chapitres` where titre_chapitre = '$chapitre_titre' and id_partie = $id_partie;");
 								if ((mysql_num_rows($select_chapitre_titre) == 0) || (mysql_num_rows($select_chapitre_titre) == 1 && mysql_result($select_chapitre_titre,0) == $id_chap)) {
 									$update_chapitre = "update `" . $tblprefix . "chapitres` SET titre_chapitre = '$chapitre_titre', objectifs_chapitre = '$chapitre_objectifs', date_modification_chapitre = ".time()." where id_chapitre = $id_chap;";
 									mysql_query($update_chapitre);
 									
	          			$date_modification_tuto = time();
	          			$update_tuto_date_modification = mysql_query("update `" . $tblprefix . "tutoriels` set date_modification_tutoriel = $date_modification_tuto where id_tutoriel = $id_tuto;");

 									redirection(chapitre_modifie,"?inc=tutorials&do=open_partie&id_part=".$id_partie."",3,"tips",1);
 								} else goback(titre_existe,2,"error",1);
    					} else goback(titre_vide,2,"error",1);
    				}
    				else {
    					goback_button();
							echo "<form method=\"POST\" action=\"\">";
    					echo "<p><u><b><font color=\"red\">*</font> " .titre_chapitre. "</b></u><br /><br /><input name=\"chapitre_titre\" type=\"text\" size=\"50\" maxlength=\"100\" value=\"".$titre_chapitre."\"></p>";							
    					echo "<br /><p><u><b>" .objectifs_chapitre. "</b></u><br />".remarque_update_objectifs."<br /><br /><textarea name=\"chapitre_objectifs\" cols=\"100\" rows=\"10\">".$objectifs_chapitre."</textarea></p>";

    					echo "<input type=\"hidden\" name=\"send\" value=\"ok\">";
    					echo "<br /><input type=\"submit\" class=\"button\" value=\"" .btnsend. "\"></form>";
    				}
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** delete_chapitre **********************
    case "delete_chapitre" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idpartie = mysql_query("select id_user, `" . $tblprefix . "parties`.id_partie from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and id_chapitre = $id_chap;");
    		if (mysql_num_rows($select_user_idpartie) == 1 && mysql_result($select_user_idpartie,0,0) == $id_user_session){
    			$id_partie = mysql_result($select_user_idpartie,0,1);
					$delete_bloc = mysql_query("delete from `" . $tblprefix . "blocs` where id_chapitre = $id_chap;");					
    			$delete_chapitre = mysql_query("delete from `" . $tblprefix . "chapitres` where id_chapitre = $id_chap;");

					locationhref_admin("?inc=tutorials&do=open_partie&id_part=".$id_partie);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** orderup_chapitre *********************
    case "orderup_chapitre" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$ce_chapitre = mysql_query ("select id_tutoriel, `" . $tblprefix . "parties`.id_partie, ordre_chapitre from `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres` where `" . $tblprefix . "chapitres`.id_partie = `" . $tblprefix . "parties`.id_partie and id_chapitre = $id_chap;");
				if (mysql_num_rows($ce_chapitre) == 1) {
					$id_tutoriel = mysql_result($ce_chapitre,0,0);
					$id_partie = mysql_result($ce_chapitre,0,1);
					$ordre_chapitre = mysql_result($ce_chapitre,0,2);
					
					$select_user = mysql_query("select id_user from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tutoriel;");
					if (mysql_num_rows($select_user) == 1 && mysql_result($select_user,0) == $id_user_session){

    				$chapitre_precedent = mysql_query ("select id_chapitre, ordre_chapitre from `" . $tblprefix . "chapitres` where ordre_chapitre < $ordre_chapitre and id_partie = $id_partie order by ordre_chapitre desc;");
						if (mysql_num_rows($chapitre_precedent) > 0) {
							$idchapitre_precedent = mysql_result($chapitre_precedent,0,0);
							$ordrechapitre_precedent = mysql_result($chapitre_precedent,0,1);
							
							$order_this_chapitre = mysql_query("update `" . $tblprefix . "chapitres` set ordre_chapitre = $ordrechapitre_precedent where id_chapitre = $id_chap;");
							$order_chapitre_precedent = mysql_query("update `" . $tblprefix . "chapitres` set ordre_chapitre = $ordre_chapitre where id_chapitre = $idchapitre_precedent;");
						}
    			}
    			locationhref_admin("?inc=tutorials&do=open_partie&id_part=".$id_partie);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** orderdown_chapitre *********************
    case "orderdown_chapitre" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$ce_chapitre = mysql_query ("select id_tutoriel, `" . $tblprefix . "parties`.id_partie, ordre_chapitre from `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres` where `" . $tblprefix . "chapitres`.id_partie = `" . $tblprefix . "parties`.id_partie and id_chapitre = $id_chap;");
				if (mysql_num_rows($ce_chapitre) == 1) {
					$id_tutoriel = mysql_result($ce_chapitre,0,0);
					$id_partie = mysql_result($ce_chapitre,0,1);
					$ordre_chapitre = mysql_result($ce_chapitre,0,2);
					
					$select_user = mysql_query("select id_user from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tutoriel;");
					if (mysql_num_rows($select_user) == 1 && mysql_result($select_user,0) == $id_user_session){

    				$chapitre_suivant = mysql_query ("select id_chapitre, ordre_chapitre from `" . $tblprefix . "chapitres` where ordre_chapitre > $ordre_chapitre and id_partie = $id_partie order by ordre_chapitre;");
						if (mysql_num_rows($chapitre_suivant) > 0) {
							$idchapitre_suivant = mysql_result($chapitre_suivant,0,0);
							$ordrechapitre_suivant = mysql_result($chapitre_suivant,0,1);
							
							$order_this_chapitre = mysql_query("update `" . $tblprefix . "chapitres` set ordre_chapitre = $ordrechapitre_suivant where id_chapitre = $id_chap;");
							$order_chapitre_suivant = mysql_query("update `" . $tblprefix . "chapitres` set ordre_chapitre = $ordre_chapitre where id_chapitre = $idchapitre_suivant;");
						}
    			}
					locationhref_admin("?inc=tutorials&do=open_partie&id_part=".$id_partie);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** publier_chapitre *********************
    case "publier_chapitre" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idpartie = mysql_query("select id_user, `" . $tblprefix . "parties`.id_partie from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and id_chapitre = $id_chap;");
    		if (mysql_num_rows($select_user_idpartie) == 1 && mysql_result($select_user_idpartie,0,0) == $id_user_session){
    			$id_partie = mysql_result($select_user_idpartie,0,1);
    			$publier_chapitre = mysql_query("update `" . $tblprefix . "chapitres` set publie_chapitre = '1' where id_chapitre = $id_chap;");
					locationhref_admin("?inc=tutorials&do=open_partie&id_part=".$id_partie);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;
    
    // ****************** depublier_chapitre *******************
    case "depublier_chapitre" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idpartie = mysql_query("select id_user, `" . $tblprefix . "parties`.id_partie from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and id_chapitre = $id_chap;");
    		if (mysql_num_rows($select_user_idpartie) == 1 && mysql_result($select_user_idpartie,0,0) == $id_user_session){
    			$id_partie = mysql_result($select_user_idpartie,0,1);
    			$depublier_chapitre = mysql_query("update `" . $tblprefix . "chapitres` set publie_chapitre = '0' where id_chapitre = $id_chap;");
					locationhref_admin("?inc=tutorials&do=open_partie&id_part=".$id_partie);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** open_chapitre ************************
    case "open_chapitre" : {
     $select_tuto = mysql_query("select `" . $tblprefix . "parties`.id_partie, `" . $tblprefix . "tutoriels`.id_tutoriel, titre_tutoriel, titre_partie, titre_chapitre, publie_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and id_chapitre = $id_chap and id_user = $id_user_session;");
     if (mysql_num_rows($select_tuto) == 1) {
     	$id_part = mysql_result($select_tuto,0,0);
     	$id_tuto = mysql_result($select_tuto,0,1);
    	$titre_tuto = html_ent(mysql_result($select_tuto,0,2));
    	$titre_tuto = readmore($titre_tuto,$max_len2);
    	$titre_part = html_ent(mysql_result($select_tuto,0,3));
    	$titre_part = readmore($titre_part,$max_len2);
			$titre_chap = html_ent(mysql_result($select_tuto,0,4));
			$titre_chap = readmore($titre_chap,$max_len2);
    	$publie_tuto = mysql_result($select_tuto,0,5);

			goback_button();

			if (isset($_GET['t']) && ctype_digit($_GET['t']))
				$page2 = intval($_GET['t']);
			else $page2 = 1;

			echo "<b>".tutoriel." : <a href=\"?inc=tutorials&do=open_tuto&id_tuto=".$id_tuto."\">".$titre_tuto."</a></b><br />";
			echo "<b>".partie." : <a href=\"?inc=tutorials&do=open_partie&id_part=".$id_part."\">".$titre_part."</a></b><br />";
			echo "<h2><center>".chapitre." : <u>".$titre_chap."</u></center></h2>";
					
			// ***************** blocs ********************
			echo "<hr /><h2><a name=\"blocs\"><font color=\"black\"><u>".blocs."</u></font></a></h2>";
			if ($publie_tuto == 2)
    		echo "<table border=\"0\"><tr><td><img border=\"0\" src=\"../images/others/add2.png\" /></a></td><td><b>".creer_bloc."</b></td></tr></table><br />";
 			else 
 			  echo "<table border=\"0\"><tr><td><a href=\"?inc=tutorials&do=create_bloc&id_chap=".$id_chap."\"><img border=\"0\" src=\"../images/others/add.png\" /></a></td><td><a href=\"?inc=tutorials&do=create_bloc&id_chap=".$id_chap."\"><b>".creer_bloc."</b></a></td></tr></table><br />";

  $select_my_blocs = mysql_query("select id_bloc, titre_bloc, publie_bloc, ordre_bloc from `" . $tblprefix . "blocs` where id_chapitre = $id_chap order by ordre_bloc;");
	$nbr_trouve = mysql_num_rows($select_my_blocs);
  if ($nbr_trouve > 0){
		$page_max = ceil($nbr_trouve / $nbr_resultats);
		if ($page <= $page_max && $page > 1 && $page_max > 1)
			$limit = ($page - 1) * $nbr_resultats;
		else {
			$limit = 0;
			$page = 1;
		}

    	$select_my_blocs_limit = mysql_query("select id_bloc, titre_bloc, publie_bloc, ordre_bloc from `" . $tblprefix . "blocs` where id_chapitre = $id_chap order by ordre_bloc limit $limit, $nbr_resultats;");

    		echo "<table width=\"100%\" align=\"center\" style=\"border: 1px solid #000000;\"><tr bgcolor=\"#f1d3bd\">\n";
				echo "\n<td class=\"affichage_table\"><b>".bloc."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".editer."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".supprimer."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".previsualiser."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".ordonner."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".action."</b></td>";
				echo "</tr>";
				$j_ordre = ($page - 1) * $nbr_resultats + 1;
				while($bloc = mysql_fetch_row($select_my_blocs_limit)){
					
					$titre_bloc = html_ent($bloc[1]);
					$titre_bloc = readmore($titre_bloc,$max_len2);

					if ($bloc[2] == 1)
						$color = "green";
					else $color = "red";
					
					echo "<tr>\n";
					echo "\n<td class=\"affichage_table\"><font color=\"".$color."\"><u><b>".$titre_bloc."</b></u></font></td>";

					if ($publie_tuto == 2)
						echo "\n<td class=\"affichage_table\"><img border=\"0\" src=\"../images/others/noedit.png\" width=\"32\" height=\"32\" /></td>";
					else
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=update_bloc&id_bloc=".$bloc[0]."\" title=\"".editer."\"><img border=\"0\" src=\"../images/others/edit.png\" width=\"32\" height=\"32\" /></a></td>";
				
					echo "\n<td class=\"affichage_table\"><a href=\"#\" onClick=\"confirmer('?inc=tutorials&do=delete_bloc&id_bloc=".$bloc[0]."&key=".$key."','".confirm_supprimer_bloc."')\" title=\"".supprimer."\"><img border=\"0\" src=\"../images/others/delete.png\" width=\"32\" height=\"32\" /></a></td>";
					
					echo "\n<td class=\"affichage_table\"><a href=\"?inc=view_tuto&chapter=".$id_chap."#".$bloc[0]."\" title=\"".previsualiser."\"><img border=\"0\" src=\"../images/others/view.png\" width=\"32\" height=\"32\" /></a></td>";
					
					echo "\n<td class=\"affichage_table\">";
					$bloc_precedent = mysql_query ("select id_bloc from `" . $tblprefix . "blocs` where ordre_bloc < $bloc[3] and id_chapitre = $id_chap order by ordre_bloc desc;");
					if (mysql_num_rows($bloc_precedent) > 0)
						echo "<a href=\"?inc=tutorials&do=orderup_bloc&id_bloc=".$bloc[0]."&key=".$key."\" title=\"".deplacer_haut."\"><img border=\"0\" src=\"../images/others/up.png\" width=\"15\" height=\"15\" /></a>";
					else
						echo "<img border=\"0\" src=\"../images/others/up2.png\" width=\"15\" height=\"15\" />";
					echo "<b> ".$j_ordre." </b>";
					$j_ordre++;
					$bloc_suivant = mysql_query ("select id_bloc from `" . $tblprefix . "blocs` where ordre_bloc > $bloc[3] and id_chapitre = $id_chap order by ordre_bloc;");
					if (mysql_num_rows($bloc_suivant) > 0)
						echo "<a href=\"?inc=tutorials&do=orderdown_bloc&id_bloc=".$bloc[0]."&key=".$key."\" title=\"".deplacer_bas."\"><img border=\"0\" src=\"../images/others/down.png\" width=\"15\" height=\"15\" /></a>";
					else echo "<img border=\"0\" src=\"../images/others/down2.png\" width=\"15\" height=\"15\" />";
					echo "</td>";
					
					if ($bloc[2] == 1)
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=depublier_bloc&id_bloc=".$bloc[0]."&key=".$key."\" title=\"".depublier_element."\"><b>".depublier."</b></a></td>";
					else
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=publier_bloc&id_bloc=".$bloc[0]."&key=".$key."\" title=\"".publier_element."\"><b>".publier."</b></a></td>";

					echo "</tr>\n";
				}
				echo "\n</table>";

		if ($page_max > 1){
			$page_precedente = $page - 1;
			$page_suivante = $page + 1;
  		echo "<br /><table border=\"0\" align=\"center\"><tr>";
			if ($page_precedente >= 1)
				echo "<td><a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."&l=".$page_precedente."&t=".$page2."#blocs\"><img border=\"0\" src=\"../images/others/precedent.png\" width=\"32\" height=\"32\" /></a></td><td><a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."&l=".$page_precedente."&t=".$page2."#blocs\"><b>".page_precedente."</b></a></td>";
			echo "<td>";
			for($i=1;$i<=$page_max;$i++){
				if ($i != $page) echo "<a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."&l=".$i."&t=".$page2."#blocs\">";
				echo "<b>".$i."</b>";
				if ($i != $page) echo "</a>";
				echo "&nbsp; ";
			}
			echo "</td>";
			if ($page_suivante <= $page_max)
				echo "<td><a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."&l=".$page_suivante."&t=".$page2."#blocs\"><b>".page_suivante."</b></a></td><td><a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."&l=".$page_suivante."&t=".$page2."#blocs\"><img border=\"0\" src=\"../images/others/suivant.png\" width=\"32\" height=\"32\" /></a></td>";
			echo "</tr></table>";
		}
		
    	} else echo pas_de_bloc;
    	
    	// ***************** QCM ********************
    	
			echo "<br /><hr /><h2><a name=\"qcm\"><font color=\"black\"><u>".qcm."</u></font></a></h2>";
			if ($publie_tuto == 2)
    		echo "<table border=\"0\"><tr><td><img border=\"0\" src=\"../images/others/add2.png\" /></a></td><td><b>".creer_qcm."</b></td></tr></table><br />";
 			else 
 			  echo "<table border=\"0\"><tr><td><a href=\"?inc=tutorials&do=create_qcm&id_chap=".$id_chap."\"><img border=\"0\" src=\"../images/others/add.png\" /></a></td><td><a href=\"?inc=tutorials&do=create_qcm&id_chap=".$id_chap."\"><b>".creer_qcm."</b></a></td></tr></table><br />";

    	$select_my_qcm = mysql_query("select * from `" . $tblprefix . "qcm` where id_chapitre = $id_chap order by ordre_qcm;");
			 $nbr_trouve = mysql_num_rows($select_my_qcm);
  		 if ($nbr_trouve > 0){
				$page_max = ceil($nbr_trouve / $nbr_resultats);
				if ($page2 <= $page_max && $page2 > 1 && $page_max > 1)
					$limit = ($page2 - 1) * $nbr_resultats;
				else {
					$limit = 0;
					$page2 = 1;
				}

    	$select_my_qcm_limit = mysql_query("select * from `" . $tblprefix . "qcm` where id_chapitre = $id_chap order by ordre_qcm limit $limit, $nbr_resultats;");

    		echo "<table width=\"100%\" align=\"center\" style=\"border: 1px solid #000000;\"><tr bgcolor=\"#f1d3bd\">\n";
				echo "\n<td class=\"affichage_table\"><b>".question."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".reponse_correcte."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".editer."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".supprimer."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".previsualiser."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".ordonner."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".action."</b></td>";
				echo "</tr>";
				$i_ordre = ($page2 - 1) * $nbr_resultats + 1;
				while($qcm = mysql_fetch_row($select_my_qcm_limit)){
					
					$titre_qcm = no_br($qcm[2]);
					$titre_qcm = readmore($titre_qcm,$max_len);
					
					$reponse_correcte = $qcm[$qcm[9]+2];
					$reponse_correcte = html_ent($reponse_correcte);
					$reponse_correcte = readmore($reponse_correcte,$max_len);

					if ($qcm[12] == 1)
						$color = "green";
					else $color = "red";
					
					echo "<tr>\n";
					echo "\n<td class=\"affichage_table\"><font color=\"".$color."\"><u><b>".$titre_qcm."</b></u></font></td>";
					
					echo "\n<td class=\"affichage_table\"><font color=\"".$color."\"><u><b>".$reponse_correcte."</b></u></font></td>";
					
					if ($publie_tuto == 2)
						echo "\n<td class=\"affichage_table\"><img border=\"0\" src=\"../images/others/noedit.png\" width=\"32\" height=\"32\" /></td>";
					else
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=update_qcm&id_qcm=".$qcm[0]."\" title=\"".editer."\"><img border=\"0\" src=\"../images/others/edit.png\" width=\"32\" height=\"32\" /></a></td>";
				
					echo "\n<td class=\"affichage_table\"><a href=\"#\" onClick=\"confirmer('?inc=tutorials&do=delete_qcm&id_qcm=".$qcm[0]."&key=".$key."','".confirm_supprimer_qcm."')\" title=\"".supprimer."\"><img border=\"0\" src=\"../images/others/delete.png\" width=\"32\" height=\"32\" /></a></td>";
					
					echo "\n<td class=\"affichage_table\"><a href=\"?inc=view_tuto&chapter=".$id_chap."#qcm\" title=\"".previsualiser."\"><img border=\"0\" src=\"../images/others/view.png\" width=\"32\" height=\"32\" /></a></td>";

					echo "\n<td class=\"affichage_table\">";
					$qcm_precedent = mysql_query ("select id_qcm from `" . $tblprefix . "qcm` where ordre_qcm < $qcm[13] and id_chapitre = $id_chap order by ordre_qcm desc;");
					if (mysql_num_rows($qcm_precedent) > 0)
						echo "<a href=\"?inc=tutorials&do=orderup_qcm&id_qcm=".$qcm[0]."&key=".$key."\" title=\"".deplacer_haut."\"><img border=\"0\" src=\"../images/others/up.png\" width=\"15\" height=\"15\" /></a>";
					else
						echo "<img border=\"0\" src=\"../images/others/up2.png\" width=\"15\" height=\"15\" />";
					echo "<b> ".$i_ordre." </b>";
					$i_ordre++;
					$qcm_suivant = mysql_query ("select id_qcm from `" . $tblprefix . "qcm` where ordre_qcm > $qcm[13] and id_chapitre = $id_chap order by ordre_qcm;");
					if (mysql_num_rows($qcm_suivant) > 0)
						echo "<a href=\"?inc=tutorials&do=orderdown_qcm&id_qcm=".$qcm[0]."&key=".$key."\" title=\"".deplacer_bas."\"><img border=\"0\" src=\"../images/others/down.png\" width=\"15\" height=\"15\" /></a>";
					else echo "<img border=\"0\" src=\"../images/others/down2.png\" width=\"15\" height=\"15\" />";
					echo "</td>";
					
					if ($qcm[12] == 1)
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=depublier_qcm&id_qcm=".$qcm[0]."&key=".$key."\" title=\"".depublier_element."\"><b>".depublier."</b></a></td>";
					else
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=publier_qcm&id_qcm=".$qcm[0]."&key=".$key."\" title=\"".publier_element."\"><b>".publier."</b></a></td>";

					echo "</tr>\n";
				}
				echo "\n</table>";

		if ($page_max > 1){
			$page_precedente = $page2 - 1;
			$page_suivante = $page2 + 1;
  		echo "<br /><table border=\"0\" align=\"center\"><tr>";
			if ($page_precedente >= 1)
				echo "<td><a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."&t=".$page_precedente."&l=".$page."#qcm\"><img border=\"0\" src=\"../images/others/precedent.png\" width=\"32\" height=\"32\" /></a></td><td><a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."&t=".$page_precedente."&l=".$page."#qcm\"><b>".page_precedente."</b></a></td>";
			echo "<td>";
			for($i=1;$i<=$page_max;$i++){
				if ($i != $page2) echo "<a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."&t=".$i."&l=".$page."#qcm\">";
				echo "<b>".$i."</b>";
				if ($i != $page2) echo "</a>";
				echo "&nbsp; ";
			}
			echo "</td>";
			if ($page_suivante <= $page_max)
				echo "<td><a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."&t=".$page_suivante."&l=".$page."#qcm\"><b>".page_suivante."</b></a></td><td><a href=\"?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."&t=".$page_suivante."&l=".$page."#qcm\"><img border=\"0\" src=\"../images/others/suivant.png\" width=\"32\" height=\"32\" /></a></td>";
			echo "</tr></table>";
		}
		
    	} else echo pas_de_qcm;

			if ($publie_tuto == 2)
				echo "<br /><hr /><img src=\"../images/icones/info.png\" /> <b>".remarque_bloc."</b>";
     } else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** create_bloc **************************
    case "create_bloc" : {
    	$select_publie_user_tuto = mysql_query("select id_user, publie_tutoriel, `" . $tblprefix . "tutoriels`.id_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and id_chapitre = $id_chap;");
     	$id_user = mysql_result($select_publie_user_tuto,0,0);
     	$publie_tuto = mysql_result($select_publie_user_tuto,0,1);
     	$id_tuto = mysql_result($select_publie_user_tuto,0,2);
     	if ($publie_tuto != 2 && $id_user == $id_user_session) {
    	
    		if (isset($_POST['bloc_titre']) && isset($_POST['bloc_contenu'])){
    		 $bloc_titre = trim($_POST['bloc_titre']);
    		 $bloc_contenu = trim($_POST['bloc_contenu']);
    		 if (!empty($bloc_titre) && !empty($bloc_contenu)){

    			$bloc_titre = escape_string($bloc_titre);
    			$bloc_contenu = escape_string($bloc_contenu);
    			
    			$select_bloc_titre = mysql_query("select id_bloc from `" . $tblprefix . "blocs` where titre_bloc = '$bloc_titre' and id_chapitre = $id_chap;");
 					if (mysql_num_rows($select_bloc_titre) == 0) {
 						$select_max_order = mysql_query("select max(ordre_bloc) from `" . $tblprefix . "blocs` where id_chapitre = $id_chap;");
 						if (mysql_num_rows($select_max_order) == 1)
 							$ordre_bloc= mysql_result($select_max_order,0) + 1;
 						else $ordre_bloc = 1;
 						
 						$insertbloc = "INSERT INTO `" . $tblprefix . "blocs` VALUES (NULL,$id_chap,'$bloc_titre','$bloc_contenu','1',$ordre_bloc);";
	          mysql_query($insertbloc,$connect);

	          $date_modification_tuto_chap = time();
	          $update_tuto_date_modification = mysql_query("update `" . $tblprefix . "tutoriels` set date_modification_tutoriel = $date_modification_tuto_chap where id_tutoriel = $id_tuto;");
						$update_chap_date_modification = mysql_query("update `" . $tblprefix . "chapitres` set date_modification_chapitre = $date_modification_tuto_chap where id_chapitre = $id_chap;");

	          $select_this_bloc = mysql_query("select id_bloc from `" . $tblprefix . "blocs` where titre_bloc = '$bloc_titre' and contenu_bloc= '$bloc_contenu' and id_chapitre = $id_chap;");
	          if (mysql_num_rows($select_this_bloc) == 1 && $_POST['exit'] == 0) {
	          	$id_bloc = mysql_result($select_this_bloc,0);
	          	$link = "?inc=tutorials&do=update_bloc&id_bloc=".$id_bloc;
	          	locationhref_admin($link);
						}
	          else {
	          	$link = "?inc=tutorials&do=open_chapitre&id_chap=".$id_chap;
	        		redirection(bloc_cree,$link,3,"tips",1);
	        	}
 					} else goback(titre_existe,2,"error",1);
 				 } else goback(titre_contenu_vide,2,"error",1);
    		}
    		else {
    			goback_button();

    			echo "<form id=\"Form_createbloc\" name=\"Form_createbloc\" method=\"POST\" action=\"\">";
    			echo "<p><u><b><font color=\"red\">*</font> " .titre_bloc. "</b></u><br /><br /><input name=\"bloc_titre\" type=\"text\" size=\"50\" maxlength=\"100\"></p>";							
    			echo "<br /><p><u><b><font color=\"red\">*</font> " .contenu_bloc. "</b></u><br /><br /><textarea name=\"bloc_contenu\" cols=\"100\" rows=\"30\"></textarea></p>";
    			echo "<br /><input type=\"hidden\" name=\"exit\" value=\"1\"><input type=\"button\" class=\"button\" value=\"" .btnsave. "\" onClick=\"document.Form_createbloc.exit.value=0;document.Form_createbloc.submit();\">&nbsp;&nbsp;&nbsp;<input type=\"submit\" class=\"button\" value=\"" .btnsend. "\"></form>";
   			}
   		} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** update_bloc **************************
    case "update_bloc" : {
    	$select_tuto_chapitre = mysql_query("select `" . $tblprefix . "blocs`.id_chapitre, id_user, publie_tutoriel, `" . $tblprefix . "tutoriels`.id_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "blocs` where `" . $tblprefix . "parties`.id_tutoriel = `" . $tblprefix . "tutoriels`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and `" . $tblprefix . "chapitres`.id_chapitre = `" . $tblprefix . "blocs`.id_chapitre and id_bloc = $id_bloc;");
    	
    	$id_chapitre = mysql_result($select_tuto_chapitre,0,0);
    	$id_user = mysql_result($select_tuto_chapitre,0,1);
    	$publie_tuto = mysql_result($select_tuto_chapitre,0,2);
    	$id_tuto = mysql_result($select_tuto_chapitre,0,3);
    	if ($publie_tuto != 2 && $id_user == $id_user_session) {
     	
    		$select_bloc_complet = mysql_query("select * from `" . $tblprefix . "blocs` where id_bloc = $id_bloc;");
    		if (mysql_num_rows($select_bloc_complet) == 1) {
    			$bloc = mysql_fetch_row($select_bloc_complet);
    			
    			$titre_bloc = html_ent($bloc[2]);
					$contenu_bloc = $bloc[3];
					
    				if (!empty($_POST['send'])){
    					$bloc_titre = trim($_POST['bloc_titre']);
    					$bloc_contenu = trim($_POST['bloc_contenu']);
    					if (!empty($bloc_titre) && !empty($bloc_contenu)){
    						$bloc_titre = escape_string($bloc_titre);
    						$bloc_contenu = escape_string($bloc_contenu);
    						$select_bloc_titre = mysql_query("select id_bloc from `" . $tblprefix . "blocs` where titre_bloc = '$bloc_titre' and id_chapitre = $id_chapitre;");
 								if ((mysql_num_rows($select_bloc_titre) == 0) || (mysql_num_rows($select_bloc_titre) == 1 && mysql_result($select_bloc_titre,0) == $id_bloc)) {
 									$update_bloc = "update `" . $tblprefix . "blocs` SET titre_bloc = '$bloc_titre', contenu_bloc = '$bloc_contenu' where id_bloc = $id_bloc;";
 									mysql_query($update_bloc);
 									
 									$date_modification_tuto_chap = time();
	          			$update_tuto_date_modification = mysql_query("update `" . $tblprefix . "tutoriels` set date_modification_tutoriel = $date_modification_tuto_chap where id_tutoriel = $id_tuto;");
									$update_chap_date_modification = mysql_query("update `" . $tblprefix . "chapitres` set date_modification_chapitre = $date_modification_tuto_chap where id_chapitre = $id_chapitre;");

	          			$select_this_bloc = mysql_query("select id_bloc from `" . $tblprefix . "blocs` where titre_bloc = '$bloc_titre' and contenu_bloc= '$bloc_contenu' and id_chapitre = $id_chapitre;");
	          			if (mysql_num_rows($select_this_bloc) == 1 && $_POST['exit'] == 0) {
	          				$id_bloc = mysql_result($select_this_bloc,0);
	          				$link = "?inc=tutorials&do=update_bloc&id_bloc=".$id_bloc;
	          				locationhref_admin($link);
									}
	          			else redirection(bloc_modifie,"?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre."",3,"tips",1);

 								} else goback(titre_existe,2,"error",1);
    					} else goback(titre_contenu_vide,2,"error",1);
    				}
    				else {
    					goback_button();
    					echo "<form id=\"Form_updatebloc\" name=\"Form_updatebloc\" method=\"POST\" action=\"\">";
    					echo "<p><u><b><font color=\"red\">*</font> " .titre_bloc. "</b></u><br /><br /><input name=\"bloc_titre\" type=\"text\" size=\"50\" maxlength=\"100\" value=\"".$titre_bloc."\"></p>";							
    					echo "<br /><p><u><b><font color=\"red\">*</font> " .contenu_bloc. "</b></u><br /><br /><textarea name=\"bloc_contenu\" cols=\"100\" rows=\"30\">".$contenu_bloc."</textarea></p>";
    			
    					echo "<input type=\"hidden\" name=\"send\" value=\"ok\">";
							echo "<br /><input type=\"hidden\" name=\"exit\" value=\"1\"><input type=\"button\" class=\"button\" value=\"" .btnsave. "\" onClick=\"document.Form_updatebloc.exit.value=0;document.Form_updatebloc.submit();\">&nbsp;&nbsp;&nbsp;<input type=\"submit\" class=\"button\" value=\"" .btnsend. "\"></form>";
    				}
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** delete_bloc **************************
    case "delete_bloc" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idchap = mysql_query("select id_user, `" . $tblprefix . "blocs`.id_chapitre from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "blocs` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and `" . $tblprefix . "chapitres`.id_chapitre = `" . $tblprefix . "blocs`.id_chapitre and id_bloc = $id_bloc;");
    		if (mysql_num_rows($select_user_idchap) == 1 && mysql_result($select_user_idchap,0,0) == $id_user_session){
    			$id_chapitre = mysql_result($select_user_idchap,0,1);
    			
					$delete_bloc = mysql_query("delete from `" . $tblprefix . "blocs` where id_bloc = $id_bloc;");					

					locationhref_admin("?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** orderup_bloc *********************
    case "orderup_bloc" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$ce_bloc = mysql_query ("select id_tutoriel, `" . $tblprefix . "blocs`.id_chapitre, ordre_bloc from `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "blocs` where `" . $tblprefix . "chapitres`.id_partie = `" . $tblprefix . "parties`.id_partie and `" . $tblprefix . "blocs`.id_chapitre = `" . $tblprefix . "chapitres`.id_chapitre and id_bloc = $id_bloc;");
				if (mysql_num_rows($ce_bloc) == 1) {
					$id_tutoriel = mysql_result($ce_bloc,0,0);
					$id_chapitre = mysql_result($ce_bloc,0,1);
					$ordre_bloc = mysql_result($ce_bloc,0,2);
					
					$select_user = mysql_query("select id_user from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tutoriel;");
					if (mysql_num_rows($select_user) == 1 && mysql_result($select_user,0) == $id_user_session){

    				$bloc_precedent = mysql_query ("select id_bloc, ordre_bloc from `" . $tblprefix . "blocs` where ordre_bloc < $ordre_bloc and id_chapitre = $id_chapitre order by ordre_bloc desc;");
						if (mysql_num_rows($bloc_precedent) > 0) {
							$idbloc_precedent = mysql_result($bloc_precedent,0,0);
							$ordrebloc_precedent = mysql_result($bloc_precedent,0,1);
							
							$order_this_bloc = mysql_query("update `" . $tblprefix . "blocs` set ordre_bloc = $ordrebloc_precedent where id_bloc = $id_bloc;");
							$order_bloc_precedent = mysql_query("update `" . $tblprefix . "blocs` set ordre_bloc = $ordre_bloc where id_bloc = $idbloc_precedent;");
						}
    			}
					locationhref_admin("?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** orderdown_bloc *********************
    case "orderdown_bloc" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$ce_bloc = mysql_query ("select id_tutoriel, `" . $tblprefix . "blocs`.id_chapitre, ordre_bloc from `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "blocs` where `" . $tblprefix . "chapitres`.id_partie = `" . $tblprefix . "parties`.id_partie and `" . $tblprefix . "blocs`.id_chapitre = `" . $tblprefix . "chapitres`.id_chapitre and id_bloc = $id_bloc;");
				if (mysql_num_rows($ce_bloc) == 1) {
					$id_tutoriel = mysql_result($ce_bloc,0,0);
					$id_chapitre = mysql_result($ce_bloc,0,1);
					$ordre_bloc = mysql_result($ce_bloc,0,2);
					
					$select_user = mysql_query("select id_user from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tutoriel;");
					if (mysql_num_rows($select_user) == 1 && mysql_result($select_user,0) == $id_user_session){

    				$bloc_suivant = mysql_query ("select id_bloc, ordre_bloc from `" . $tblprefix . "blocs` where ordre_bloc > $ordre_bloc and id_chapitre = $id_chapitre order by ordre_bloc;");
						if (mysql_num_rows($bloc_suivant) > 0) {
							$idbloc_suivant = mysql_result($bloc_suivant,0,0);
							$ordrebloc_suivant = mysql_result($bloc_suivant,0,1);
							
							$order_this_bloc = mysql_query("update `" . $tblprefix . "blocs` set ordre_bloc = $ordrebloc_suivant where id_bloc = $id_bloc;");
							$order_bloc_suivant = mysql_query("update `" . $tblprefix . "blocs` set ordre_bloc = $ordre_bloc where id_bloc = $idbloc_suivant;");
						}
    			}
					locationhref_admin("?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** publier_bloc *************************
    case "publier_bloc" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idchap = mysql_query("select id_user, `" . $tblprefix . "blocs`.id_chapitre from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "blocs` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and `" . $tblprefix . "chapitres`.id_chapitre = `" . $tblprefix . "blocs`.id_chapitre and id_bloc = $id_bloc;");
    		if (mysql_num_rows($select_user_idchap) == 1 && mysql_result($select_user_idchap,0,0) == $id_user_session){
    			$id_chapitre = mysql_result($select_user_idchap,0,1);
    			$publier_bloc = mysql_query("update `" . $tblprefix . "blocs` set publie_bloc = '1' where id_bloc = $id_bloc;");
					locationhref_admin("?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;
    
    // ****************** depublier_bloc ***********************
    case "depublier_bloc" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idchap = mysql_query("select id_user, `" . $tblprefix . "blocs`.id_chapitre from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "blocs` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and `" . $tblprefix . "chapitres`.id_chapitre = `" . $tblprefix . "blocs`.id_chapitre and id_bloc = $id_bloc;");
    		if (mysql_num_rows($select_user_idchap) == 1 && mysql_result($select_user_idchap,0,0) == $id_user_session){
    			$id_chapitre = mysql_result($select_user_idchap,0,1);
    			$depublier_bloc = mysql_query("update `" . $tblprefix . "blocs` set publie_bloc = '0' where id_bloc = $id_bloc;");
					locationhref_admin("?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre);
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** create_qcm **************************
    case "create_qcm" : {
    	$select_publie_user_tuto = mysql_query("select id_user, publie_tutoriel, `" . $tblprefix . "tutoriels`.id_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and id_chapitre = $id_chap;");
     	$id_user = mysql_result($select_publie_user_tuto,0,0);
     	$publie_tuto = mysql_result($select_publie_user_tuto,0,1);
     	$id_tuto = mysql_result($select_publie_user_tuto,0,2);
     	if ($publie_tuto != 2 && $id_user == $id_user_session) {
     		if (!empty($_POST['send'])) {
     		 if (!isset($_SESSION['random_key']) || $_SESSION['random_key'] != $_POST['random']){
    	 		$_SESSION['random_key'] = $_POST['random'];
     			$text_question = trim($_POST['text_question']);
     			if (!empty($text_question) && !empty($_POST['reponse_correcte'])){
						$reponses_tab = array();
     				$text_question = escape_string($text_question);
     				$reponse1 = escape_string(trim($_POST['reponse1']));
     				$reponse2 = escape_string(trim($_POST['reponse2']));
     				$reponse3 = escape_string(trim($_POST['reponse3']));
     				$reponse4 = escape_string(trim($_POST['reponse4']));
     				$reponse5 = escape_string(trim($_POST['reponse5']));
     				$reponse6 = escape_string(trim($_POST['reponse6']));
     				for ($i=1;$i<7;$i++){
     					$variable_rep = "reponse".$i;
     					if (!empty($$variable_rep))
     						$reponses_tab[] = $$variable_rep;
     				}
     				if (count($reponses_tab)>1) {
     					if (ctype_digit($_POST['reponse_correcte']))
     						$reponse_correcte = intval($_POST['reponse_correcte']);
     					else $reponse_correcte = 1;
     					
     					$variable_rep = "reponse".$reponse_correcte;
     					if (!empty($$variable_rep)){
     				
     						$select_max_order = mysql_query("select max(ordre_qcm) from `" . $tblprefix . "qcm` where id_chapitre = $id_chap;");
 								if (mysql_num_rows($select_max_order) == 1)
 									$ordre_qcm = mysql_result($select_max_order,0) + 1;
 								else $ordre_qcm = 1;

 								$insertqcm = "INSERT INTO `" . $tblprefix . "qcm` VALUES (NULL,$id_chap,'$text_question','$reponse1','$reponse2','$reponse3','$reponse4','$reponse5','$reponse6','$reponse_correcte',0,0,'1',$ordre_qcm);";
	          		mysql_query($insertqcm,$connect);

	          		$date_modification_tuto_chap = time();
	          		$update_tuto_date_modification = mysql_query("update `" . $tblprefix . "tutoriels` set date_modification_tutoriel = $date_modification_tuto_chap where id_tutoriel = $id_tuto;");
								$update_chap_date_modification = mysql_query("update `" . $tblprefix . "chapitres` set date_modification_chapitre = $date_modification_tuto_chap where id_chapitre = $id_chap;");

	          		$link = "?inc=tutorials&do=open_chapitre&id_chap=".$id_chap."#qcm";
	          		redirection(qcm_cree,$link,3,"tips",1);
	          	} else goback(reponse_correcte_nonvide,2,"error",1);
	          } else goback(reponse_min_qcm,2,"error",1);
     			} else goback(champ_manq_qcm,2,"error",1);
				 } else goback(err_data_saved,2,"error",1);
				}
				else {
					goback_button();
					echo "<form method=\"POST\" action=\"\">";
					echo "\n<p><u><b><font color=\"red\">*</font> " .question. " : </b></u><br /><br /><textarea name=\"text_question\" cols=\"100\" rows=\"10\"></textarea><br /></p>";
	      	echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"1\"> " .reponse. " 1 : </b><input name=\"reponse1\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"\"></p>";
	      	echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"2\"> " .reponse. " 2 : </b><input name=\"reponse2\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"\"></p>";
	      	echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"3\"> " .reponse. " 3 : </b><input name=\"reponse3\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"\"></p>";
	      	echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"4\"> " .reponse. " 4 : </b><input name=\"reponse4\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"\"></p>";
	      	echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"5\"> " .reponse. " 5 : </b><input name=\"reponse5\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"\"></p>";
	      	echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"6\"> " .reponse. " 6 : </b><input name=\"reponse6\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"\"></p>";
	      	echo "\n<p><b>- ".remplir_qcm."<br />- ".qcm_selectionner_reponse."</b><br /><br />";
	      	echo "\n<input type=\"hidden\" name=\"send\" value=\"ok\"><input type=\"hidden\" name=\"random\" value=\"".fonc_rand(16)."\" /><input type=\"submit\" class=\"button\" value=\"" .btnsend. "\"></form></p>";
				}
   		} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** update_qcm **************************
    case "update_qcm" : {
    	$select_tuto_chapitre = mysql_query("select `" . $tblprefix . "qcm`.id_chapitre, id_user, publie_tutoriel, `" . $tblprefix . "tutoriels`.id_tutoriel from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "qcm` where `" . $tblprefix . "parties`.id_tutoriel = `" . $tblprefix . "tutoriels`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and `" . $tblprefix . "chapitres`.id_chapitre = `" . $tblprefix . "qcm`.id_chapitre and id_qcm = $id_qcm;");
    	
    	$id_chapitre = mysql_result($select_tuto_chapitre,0,0);
    	$id_user = mysql_result($select_tuto_chapitre,0,1);
    	$publie_tuto = mysql_result($select_tuto_chapitre,0,2);
    	$id_tuto = mysql_result($select_tuto_chapitre,0,3);
    	if ($publie_tuto != 2 && $id_user == $id_user_session) {

    		$select_qcm_complet = mysql_query("select * from `" . $tblprefix . "qcm` where id_qcm = $id_qcm;");
    		if (mysql_num_rows($select_qcm_complet) == 1) {
    			$qcm = mysql_fetch_row($select_qcm_complet);

    			$question_qcm = $qcm[2];
					$reponse1_qcm = html_ent($qcm[3]);
					$reponse2_qcm = html_ent($qcm[4]);
					$reponse3_qcm = html_ent($qcm[5]);
					$reponse4_qcm = html_ent($qcm[6]);
					$reponse5_qcm = html_ent($qcm[7]);
					$reponse6_qcm = html_ent($qcm[8]);
					$reponse_correcte = $qcm[9];
					function check_qcm($reponse,$reponse_correcte){
						if ($reponse == $reponse_correcte)
							return " checked=\"checked\"";
					}

     			if (!empty($_POST['send'])) {
     			 if (!isset($_SESSION['random_key']) || $_SESSION['random_key'] != $_POST['random']){
    	 			$_SESSION['random_key'] = $_POST['random'];
     				$text_question = trim($_POST['text_question']);
     				if (!empty($text_question) && !empty($_POST['reponse_correcte'])){
							$reponses_tab = array();
     					$text_question = escape_string($text_question);
     					$reponse1 = escape_string(trim($_POST['reponse1']));
     					$reponse2 = escape_string(trim($_POST['reponse2']));
     					$reponse3 = escape_string(trim($_POST['reponse3']));
     					$reponse4 = escape_string(trim($_POST['reponse4']));
     					$reponse5 = escape_string(trim($_POST['reponse5']));
     					$reponse6 = escape_string(trim($_POST['reponse6']));
     					for ($i=1;$i<7;$i++){
     						$variable_rep = "reponse".$i;
     						if (!empty($$variable_rep))
     							$reponses_tab[] = $$variable_rep;
     					}
     					if (count($reponses_tab)>1) {
     						if (ctype_digit($_POST['reponse_correcte']))
     							$reponse_correcte = intval($_POST['reponse_correcte']);
     						else $reponse_correcte = 1;
     					
     						$variable_rep = "reponse".$reponse_correcte;
     						if (!empty($$variable_rep)){
     				
     							$select_max_order = mysql_query("select max(ordre_qcm) from `" . $tblprefix . "qcm` where id_chapitre = $id_chap;");
 									if (mysql_num_rows($select_max_order) == 1)
 										$ordre_qcm = mysql_result($select_max_order,0) + 1;
 									else $ordre_qcm = 1;

 									$update_qcm = "update `" . $tblprefix . "qcm` SET question_qcm = '$text_question', reponse1_qcm = '$reponse1', reponse2_qcm = '$reponse2', reponse3_qcm = '$reponse3', reponse4_qcm = '$reponse4', reponse5_qcm = '$reponse5', reponse6_qcm = '$reponse6', reponse_correcte = '$reponse_correcte' where id_qcm = $id_qcm;";
 									mysql_query($update_qcm);
 									
 									$date_modification_tuto_chap = time();
	          			$update_tuto_date_modification = mysql_query("update `" . $tblprefix . "tutoriels` set date_modification_tutoriel = $date_modification_tuto_chap where id_tutoriel = $id_tuto;");
									$update_chap_date_modification = mysql_query("update `" . $tblprefix . "chapitres` set date_modification_chapitre = $date_modification_tuto_chap where id_chapitre = $id_chapitre;");

 									redirection(qcm_modifie,"?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre."#qcm",3,"tips",1);

	          		} else goback(reponse_correcte_nonvide,2,"error",1);
	          	} else goback(reponse_min_qcm,2,"error",1);
     				} else goback(champ_manq_qcm,2,"error",1);
					 } else goback(err_data_saved,2,"error",1);
					}
					else {
						goback_button();
						echo "<form method=\"POST\" action=\"\">";
						echo "\n<p><u><b><font color=\"red\">*</font> " .question. " : </b></u><br /><br /><textarea name=\"text_question\" cols=\"100\" rows=\"10\">".$question_qcm."</textarea><br /></p>";
	      		echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"1\"".check_qcm(1,$reponse_correcte)."> " .reponse. " 1 : </b><input name=\"reponse1\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"".$reponse1_qcm."\"></p>";
	      		echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"2\"".check_qcm(2,$reponse_correcte)."> " .reponse. " 2 : </b><input name=\"reponse2\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"".$reponse2_qcm."\"></p>";
	      		echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"3\"".check_qcm(3,$reponse_correcte)."> " .reponse. " 3 : </b><input name=\"reponse3\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"".$reponse3_qcm."\"></p>";
	      		echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"4\"".check_qcm(4,$reponse_correcte)."> " .reponse. " 4 : </b><input name=\"reponse4\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"".$reponse4_qcm."\"></p>";
	      		echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"5\"".check_qcm(5,$reponse_correcte)."> " .reponse. " 5 : </b><input name=\"reponse5\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"".$reponse5_qcm."\"></p>";
	      		echo "\n<p><b><input name=\"reponse_correcte\" type=\"radio\" value=\"6\"".check_qcm(6,$reponse_correcte)."> " .reponse. " 6 : </b><input name=\"reponse6\" type=\"text\" size=\"66\" maxlength=\"200\" value=\"".$reponse6_qcm."\"></p>";
	      		echo "\n<p><b>- ".remplir_qcm."<br />- ".qcm_selectionner_reponse."</b><br /><br />";
	      		echo "\n<input type=\"hidden\" name=\"send\" value=\"ok\"><input type=\"hidden\" name=\"random\" value=\"".fonc_rand(16)."\" /><input type=\"submit\" class=\"button\" value=\"" .btnsend. "\"></form></p>";
					}
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** delete_qcm **************************
    case "delete_qcm" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idchap = mysql_query("select id_user, `" . $tblprefix . "qcm`.id_chapitre from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "qcm` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and `" . $tblprefix . "chapitres`.id_chapitre = `" . $tblprefix . "qcm`.id_chapitre and id_qcm = $id_qcm;");
    		if (mysql_num_rows($select_user_idchap) == 1 && mysql_result($select_user_idchap,0,0) == $id_user_session){
    			$id_chapitre = mysql_result($select_user_idchap,0,1);

					$delete_qcm = mysql_query("delete from `" . $tblprefix . "qcm` where id_qcm = $id_qcm;");					

					locationhref_admin("?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre."#qcm");
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** orderup_qcm *********************
    case "orderup_qcm" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$ce_qcm = mysql_query ("select id_tutoriel, `" . $tblprefix . "qcm`.id_chapitre, ordre_qcm from `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "qcm` where `" . $tblprefix . "chapitres`.id_partie = `" . $tblprefix . "parties`.id_partie and `" . $tblprefix . "qcm`.id_chapitre = `" . $tblprefix . "chapitres`.id_chapitre and id_qcm = $id_qcm;");
				if (mysql_num_rows($ce_qcm) == 1) {
					$id_tutoriel = mysql_result($ce_qcm,0,0);
					$id_chapitre = mysql_result($ce_qcm,0,1);
					$ordre_qcm = mysql_result($ce_qcm,0,2);
					
					$select_user = mysql_query("select id_user from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tutoriel;");
					if (mysql_num_rows($select_user) == 1 && mysql_result($select_user,0) == $id_user_session){

    				$qcm_precedent = mysql_query ("select id_qcm, ordre_qcm from `" . $tblprefix . "qcm` where ordre_qcm < $ordre_qcm and id_chapitre = $id_chapitre order by ordre_qcm desc;");
						if (mysql_num_rows($qcm_precedent) > 0) {
							$idqcm_precedent = mysql_result($qcm_precedent,0,0);
							$ordreqcm_precedent = mysql_result($qcm_precedent,0,1);
							
							$order_this_qcm = mysql_query("update `" . $tblprefix . "qcm` set ordre_qcm = $ordreqcm_precedent where id_qcm = $id_qcm;");
							$order_qcm_precedent = mysql_query("update `" . $tblprefix . "qcm` set ordre_qcm = $ordre_qcm where id_qcm = $idqcm_precedent;");
						}
    			}
    			locationhref_admin("?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre."#qcm");
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** orderdown_qcm *********************
    case "orderdown_qcm" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$ce_qcm = mysql_query ("select id_tutoriel, `" . $tblprefix . "qcm`.id_chapitre, ordre_qcm from `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "qcm` where `" . $tblprefix . "chapitres`.id_partie = `" . $tblprefix . "parties`.id_partie and `" . $tblprefix . "qcm`.id_chapitre = `" . $tblprefix . "chapitres`.id_chapitre and id_qcm = $id_qcm;");
				if (mysql_num_rows($ce_qcm) == 1) {
					$id_tutoriel = mysql_result($ce_qcm,0,0);
					$id_chapitre = mysql_result($ce_qcm,0,1);
					$ordre_qcm = mysql_result($ce_qcm,0,2);
					
					$select_user = mysql_query("select id_user from `" . $tblprefix . "tutoriels` where id_tutoriel = $id_tutoriel;");
					if (mysql_num_rows($select_user) == 1 && mysql_result($select_user,0) == $id_user_session){

    				$qcm_suivant = mysql_query ("select id_qcm, ordre_qcm from `" . $tblprefix . "qcm` where ordre_qcm > $ordre_qcm and id_chapitre = $id_chapitre order by ordre_qcm;");
						if (mysql_num_rows($qcm_suivant) > 0) {
							$idqcm_suivant = mysql_result($qcm_suivant,0,0);
							$ordreqcm_suivant = mysql_result($qcm_suivant,0,1);
							
							$order_this_qcm = mysql_query("update `" . $tblprefix . "qcm` set ordre_qcm = $ordreqcm_suivant where id_qcm = $id_qcm;");
							$order_qcm_suivant = mysql_query("update `" . $tblprefix . "qcm` set ordre_qcm = $ordre_qcm where id_qcm = $idqcm_suivant;");
						}
    			}
    			locationhref_admin("?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre."#qcm");
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** publier_qcm *************************
    case "publier_qcm" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idchap = mysql_query("select id_user, `" . $tblprefix . "qcm`.id_chapitre from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "qcm` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and `" . $tblprefix . "chapitres`.id_chapitre = `" . $tblprefix . "qcm`.id_chapitre and id_qcm = $id_qcm;");
    		if (mysql_num_rows($select_user_idchap) == 1 && mysql_result($select_user_idchap,0,0) == $id_user_session){
    			$id_chapitre = mysql_result($select_user_idchap,0,1);
    			$publier_qcm = mysql_query("update `" . $tblprefix . "qcm` set publie_qcm = '1' where id_qcm = $id_qcm;");
					locationhref_admin("?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre."#qcm");
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;
    
    // ****************** depublier_qcm ***********************
    case "depublier_qcm" : {
    	if (isset($_GET['key']) && $_GET['key'] == $key){
    		$select_user_idchap = mysql_query("select id_user, `" . $tblprefix . "qcm`.id_chapitre from `" . $tblprefix . "tutoriels`, `" . $tblprefix . "parties`, `" . $tblprefix . "chapitres`, `" . $tblprefix . "qcm` where `" . $tblprefix . "tutoriels`.id_tutoriel = `" . $tblprefix . "parties`.id_tutoriel and `" . $tblprefix . "parties`.id_partie = `" . $tblprefix . "chapitres`.id_partie and `" . $tblprefix . "chapitres`.id_chapitre = `" . $tblprefix . "qcm`.id_chapitre and id_qcm = $id_qcm;");
    		if (mysql_num_rows($select_user_idchap) == 1 && mysql_result($select_user_idchap,0,0) == $id_user_session){
    			$id_chapitre = mysql_result($select_user_idchap,0,1);
    			$depublier_qcm = mysql_query("update `" . $tblprefix . "qcm` set publie_qcm = '0' where id_qcm = $id_qcm;");
					locationhref_admin("?inc=tutorials&do=open_chapitre&id_chap=".$id_chapitre."#qcm");
    		} else locationhref_admin("?inc=tutorials");
    	} else locationhref_admin("?inc=tutorials");
    } break;

    // ****************** liste_tutos **************************
    default : {
    	echo "<table border=\"0\"><tr><td><a href=\"?inc=tutorials&do=create_tuto\"><img border=\"0\" src=\"../images/others/add.png\" /></a></td><td><a href=\"?inc=tutorials&do=create_tuto\"><b>".creer_tuto."</b></a></td></tr></table><br />";

  $select_my_tutos = mysql_query("select * from `" . $tblprefix . "tutoriels` where id_user = $id_user_session;");
	$nbr_trouve = mysql_num_rows($select_my_tutos);
  if ($nbr_trouve > 0){
		$page_max = ceil($nbr_trouve / $nbr_resultats);
		if ($page <= $page_max && $page > 1 && $page_max > 1)
			$limit = ($page - 1) * $nbr_resultats;
		else {
			$limit = 0;
			$page = 1;
		}

    $select_my_tutos_limit = mysql_query("select * from `" . $tblprefix . "tutoriels` where id_user = $id_user_session limit $limit, $nbr_resultats;");

    		echo "<table width=\"100%\" align=\"center\" style=\"border: 1px solid #000000;\"><tr bgcolor=\"#f1d3bd\">\n";
				echo "\n<td class=\"affichage_table\"><b>".mes_tutoriels."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".editer."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".supprimer."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".previsualiser."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".etat_tutoriel."</b></td>";
				echo "\n<td class=\"affichage_table\"><b>".action."</b></td>";
				echo "</tr>";

				while($tutoriel = mysql_fetch_row($select_my_tutos_limit)){
					
					$titre_tutoriel = html_ent($tutoriel[2]);
					$titre_tutoriel = readmore($titre_tutoriel,$max_len);
					
					if ($tutoriel[8] == 2)
						$color = "green";
					else $color = "red";
					
					echo "<tr>\n";
					echo "\n<td class=\"affichage_table\" width=\"45%\"><a href=\"?inc=tutorials&do=open_tuto&id_tuto=".$tutoriel[0]."\" title=\"".ouvrir_tuto."\"><font color=\"".$color."\"><u><b>".$titre_tutoriel."</b></u></font></a></td>";
					if ($tutoriel[8] == 2)
						echo "\n<td class=\"affichage_table\"><img border=\"0\" src=\"../images/others/noedit.png\" width=\"32\" height=\"32\" /></td>";
					else
						echo "\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=update_tuto&id_tuto=".$tutoriel[0]."\" title=\"".editer."\"><img border=\"0\" src=\"../images/others/edit.png\" width=\"32\" height=\"32\" /></a></td>";

					echo "\n<td class=\"affichage_table\"><a href=\"#\" onClick=\"confirmer('?inc=tutorials&do=delete_tuto&id_tuto=".$tutoriel[0]."&key=".$key."','".confirm_supprimer_tuto."')\" title=\"".supprimer."\"><img border=\"0\" src=\"../images/others/delete.png\" width=\"32\" height=\"32\" /></a></td>";
					echo "\n<td class=\"affichage_table\"><a href=\"?inc=view_tuto&tutorial=".$tutoriel[0]."\" title=\"".previsualiser."\"><img border=\"0\" src=\"../images/others/view.png\" width=\"32\" height=\"32\" /></a></td>";

					if ($tutoriel[8] == 2)
						echo "\n<td class=\"affichage_table\">".valide2."</td>\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=depublier_tuto&id_tuto=".$tutoriel[0]."&key=".$key."\" title=\"".depublier_element."\"><b>".depublier."</b></a></td>";
					else if ($tutoriel[8] == 1)
						echo "\n<td class=\"affichage_table\">".valide1."</td>\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=depublier_tuto&id_tuto=".$tutoriel[0]."&key=".$key."\" title=\"".annuler_validation."\"><b>".annuler_validation."</b></a></td>";
					else
						echo "\n<td class=\"affichage_table\">".valide0."</td>\n<td class=\"affichage_table\"><a href=\"?inc=tutorials&do=publier_tuto&id_tuto=".$tutoriel[0]."&key=".$key."\" title=\"".publier_element."\"><b>".demander_validation."</b></a></td>";

					echo "</tr>\n";
				}
				echo "\n</table>";
				
		if ($page_max > 1){
			$page_precedente = $page - 1;
			$page_suivante = $page + 1;
  		echo "<br /><table border=\"0\" align=\"center\"><tr>";
			if ($page_precedente >= 1)
				echo "<td><a href=\"?inc=tutorials&l=".$page_precedente."\"><img border=\"0\" src=\"../images/others/precedent.png\" width=\"32\" height=\"32\" /></a></td><td><a href=\"?inc=tutorials&l=".$page_precedente."\"><b>".page_precedente."</b></a></td>";
			echo "<td>";
			for($i=1;$i<=$page_max;$i++){
				if ($i != $page) echo "<a href=\"?inc=tutorials&l=".$i."\">";
				echo "<b>".$i."</b>";
				if ($i != $page) echo "</a>";
				echo "&nbsp; ";
			}
			echo "</td>";
			if ($page_suivante <= $page_max)
				echo "<td><a href=\"?inc=tutorials&l=".$page_suivante."\"><b>".page_suivante."</b></a></td><td><a href=\"?inc=tutorials&l=".$page_suivante."\"><img border=\"0\" src=\"../images/others/suivant.png\" width=\"32\" height=\"32\" /></a></td>";
			echo "</tr></table>";
		}
		
				echo "<br /><img src=\"../images/icones/info.png\" /> <b>".remarque_tuto."</b>";
    	} else echo pas_encore_tutoriel;
    }
  }
} else echo restricted_access;

?>